Please help. I've been stuck on this for days. I have a sample web service, written in C# that I'd like to have be able to call into a DLL written in C++ (also in the .NET Studio). I can compile and build both pieces, but I'll be hanged if I can get the call to work at run-time.
My service code (snippet) looks like this:
public class Service1 : System.Web.Services.WebService
{
[DllImport
(
"C:\\MyThunk\\Debug\\MyThunk.dll",
EntryPoint="MyDocThunk",
ExactSpelling=false,
SetLastError=true,
CharSet = CharSet.Unicode
)]
static extern int
MyDocThunk
(
[MarshalAs(UnmanagedType.LPWStr)]string aString,
[MarshalAs(UnmanagedType.LPWStr)]string anotherString,
);
...
string astring1;
string astring2;
// call the imported fn():
Service1.MyDocThunk( astring1, astring2 );
...
}
My DLL code (snippet) looks like:
extern int __declspec( dllexport)
MyDocThunk
(
WCHAR *string1,
WCHAR *string1
)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// normal function body here
CString myWorkString;
// ignoring the bloody inputs for now...
return 0;
}
The DLL is build __stdcall so as to mate up with what I understand is the default .NET behavior for DllImport.
I can put a breakpoint on the call to MyDocThunk in the web service and I hit it. If I try to continue, or step in, I don't get an exception, but IE pops back up claiming that the web page cannot be found (an HTTP 500 Infernal server error). Of course, if I remove the external call, then my simple Web service operates as expected. I really need to be able to "thunk" out to an unmanaged DLL (for reasons I won't go into here).
I admit I'm a newbie at C# and .NET, but the total lack of error info and what seems to be a fairly simple call failing is frustrating, to say the least.
I've even tried doing the DllImport as an ordinal to avoid name mangling issues. No dice. Something so simple should not be so hard (and the error info so well hidden). WTFO!
Can someone point at what I'm doing wrong?
TIA,
Bill
From you code I cannot see anything that is wrong, so possibly it's your
ASPNET account do not have necessary permission to bind to the DLL...
It may also be worthwhile to check the following link to see whatever step
is missing(just a random search from Google for webservice and interop):
http://support.sas.com/rnd/eai/samples/DotNetWebService/installandrun.html
> Please help. I've been stuck on this for days. I have a sample web service, written in C# that I'd like to have be able to call into a DLL
written in C++ (also in the .NET Studio). I can compile and build both
pieces, but I'll be hanged if I can get the call to work at run-time.
> My service code (snippet) looks like this:
>
[quoted text clipped - 52 lines]
>
> I can put a breakpoint on the call to MyDocThunk in the web service and I hit it. If I try to continue, or step in, I don't get an exception, but IE
pops back up claiming that the web page cannot be found (an HTTP 500
Infernal server error). Of course, if I remove the external call, then my
simple Web service operates as expected. I really need to be able to
"thunk" out to an unmanaged DLL (for reasons I won't go into here).
> I admit I'm a newbie at C# and .NET, but the total lack of error info and what seems to be a fairly simple call failing is frustrating, to say the
least.
> I've even tried doing the DllImport as an ordinal to avoid name mangling issues. No dice. Something so simple should not be so hard (and the error
info so well hidden). WTFO!
> Can someone point at what I'm doing wrong?
>
> TIA,
> Bill
Bill Wilhelm - 24 Nov 2004 13:10 GMT
I can run the web service just fine without the external DLL call. If permissions or the like *were* the problem, where would there be some kind of log entry to indicate such?
Lau Lei Cheong - 25 Nov 2004 08:18 GMT
Since permission error on calling external DLLs is not occurred in managed
code, it's unlikely the autolog will get anything better then "HTTP 500
error occurred" but you can check.
The default location would be at: C:\WINDOWS\System32\LogFiles
> I can run the web service just fine without the external DLL call. If permissions or the like *were* the problem, where would there be some kind
of log entry to indicate such?