Dear everyone:
I know I can call a dll by c# like this:
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern int MessageBox(int hWnd, String text,
String caption, uint type);
but now I want to call a lib file created by VC6.0,for example "a.lib".
Could anybody tell me how to do it?
Thanks!
Tom
Klaus H. Probst - 07 Jul 2004 20:06 GMT
Nope. It implies the ability to link statically, and .NET won't do that.

Signature
Klaus H. Probst, MVP
http://www.vbbox.com/
> Dear everyone:
> I know I can call a dll by c# like this:
[quoted text clipped - 9 lines]
>
> Tom
Richard Grimes [MVP] - 02 Aug 2004 20:14 GMT
> Dear everyone:
> I know I can call a dll by c# like this:
[quoted text clipped - 7 lines]
> "a.lib". Could anybody tell me how to do it?
> Thanks!
you have two options:
1) use unmanaged C++ to expose the lib functions as exported (unmanaged) DLL
functions
2) use managed C++ to expose a managed class
Managed C++ can use unmanaged .lib files, which is why #2 works, however,
there are issues with mixing managed and unmanaged code in a library
assembly (caused by the Win32 DLL loader holding various locks which could
cuase a deadlock). #1 is the safest option.
Richard

Signature
my email evpuneqt@zicf.bet is encrypted with ROT13 (www.rot13.org)
sign up for my free .NET newsletter at
http://www.wd-mag.com/newsletters/
alanrn - 03 Aug 2004 01:21 GMT
So, how is option #1 accomplished?
.ARN.
> > Dear everyone:
> > I know I can call a dll by c# like this:
[quoted text clipped - 20 lines]
>
> Richard
Richard Grimes [MVP] - 08 Aug 2004 17:37 GMT
>> 1) use unmanaged C++ to expose the lib functions as exported
>> (unmanaged) DLL functions
>
> So, how is option #1 accomplished?
Well, if you have a lib that provides this function:
bool test_func(int param1, char* param2);
you create a DLL with this function:
extern "C" __declspec(dllexport) bool Test_Func(int param1, char* param2)
{
return test_func(param1, param2);
}
Richard

Signature
my email evpuneqt@zicf.bet is encrypted with ROT13 (www.rot13.org)
sign up for my free .NET newsletter at
http://www.wd-mag.com/newsletters/