Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2004

Tip: Looking for answers? Try searching our database.

calling existing DLL from .NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill Wilhelm - 23 Nov 2004 21:02 GMT
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
Lau Lei Cheong - 24 Nov 2004 01:36 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.