Re: Can C# Call This DLL?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 10/18/04


Date: Mon, 18 Oct 2004 08:58:04 -0400

Mark,

    While you are using the stdcall convention for the functions, it's not
possible to tell whether or not you are exploring the functions correctly.
My guess is that yes, the functions are exported correctly, so you should
have no problem using this.

    However, the only thing that is of concern is the memory management
routine. It looks like there is a routine for allocating memory, but I
can't see anything for deallocating memory. If you have that defined, then
you should be alright.

    Other than that, there is no reason why you shouldn't be able to use
this from .NET.

    Hope this helps.

-- 
               - Nicholas Paldino [.NET/C# MVP]
               - mvp@spam.guard.caspershouse.com
"Mark Jerde" <mark.jerde@verizon.no.spam.net> wrote in message 
news:%23UdwDBRtEHA.2956@TK2MSFTNGP12.phx.gbl...
>I need to call a Win32 DLL.  The API supports both Windows and Linux, but
> I'm only concerned with Windows.  I'd like advice whether I can use C# or
> whether I'll have to dust off my old C++ books.  I would prefer to learn 
> C#
> rather than go back to C++.
>
> The API starts with
>
> #ifdef (WIN32)
> #define MyAPI __stdcall
> #else
> #define MyAPI
> #endif
>
> There are bitmap mask #define statements.
>
> All integer values are little-endian.
>
> There are many "typedef" and "typedef struct" statements with char, const,
> void, sint8, uint8, uint16, uint32, and sint32 elements, arrays and
> pointers.
>
> There are "typedef struct" statements with union elements.
>
> To ease cross-platform use, the API defines its own memory management. 
> This
> is one typedef:
>
> typedef void * (MyAPI *MyAPI_REALLOC)
>   (void * Memblock,
>   uint32 Size,
>   void * Allocref);
>
> And the part I'm the least sure can be done in C# is the asynchronous 
> event
> mechanism.  Here is one of the typefefs.
>
> typedef MyAPI_RETURN (MyAPI *MyAPI_ModuleEventHandler)
>   (const MyAPI_UUID *UUID,
>   void* AppNotifyCallbackCtx,
>   MyAPI_ID ID,
>   uint32 Reserved,
>   MyAPI_Event EventType);
>
> Can C# easily work with this API? (*)
>
> Thanks!
>
>   -- Mark
>
> (*) Several years ago I wrote some ugly VB6 code to deal with a DLL that 
> had
> VB-unfriendly pointers and unicode strings.  Therefore I assume it is
> "possible" to use this DLL from C#.  I guess I'm asking whether or not it 
> is
> "easy" or "reasonable" to call the DLL from C#.
>
> 


Relevant Pages

  • Can C# Call This DLL?
    ... I need to call a Win32 DLL. ... The API supports both Windows and Linux, ... I'm only concerned with Windows. ... (void * Memblock, ...
    (microsoft.public.dotnet.languages.csharp)
  • Can C# Call This DLL?
    ... I need to call a Win32 DLL. ... The API supports both Windows and Linux, ... I'm only concerned with Windows. ... (void * Memblock, ...
    (microsoft.public.vc.language)
  • Re: Can C# Call This DLL?
    ... >I need to call a Win32 DLL. ... The API supports both Windows and Linux, but> I'm only concerned with Windows. ... > There are many "typedef" and "typedef struct" statements with char, const, ... > (void * Memblock, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: RUNDLL32.EXE
    ... 0x66800000 0x155000 Windows Shell Common Dll ... 0x75FA0000 0xA000 BSD Socket API for Windows ... 0x794D0000 0x15000 Microsoft WinSock Extension APIs ...
    (comp.security.firewalls)
  • Re: ZoneAlarm -- Alert for "Run a DLL"
    ... I am blocking it from accessing the internet also... ... DLL file called SENSAPI.DLL. ... 0x60000000 0x5000 SENS Connectivity API DLL ... 0x794D0000 0x15000 Microsoft WinSock Extension APIs ...
    (comp.security.firewalls)