开发者

How to Import a C/C++ dll to .NET application

开发者 https://www.devze.com 2023-01-10 18:54 出处:网络
In my new project I want to use a existing C C++ functions . For that I would need to add the C/C++ dlls to C# project.

In my new project I want to use a existing C C++ functions . For that I would need to add the C/C++ dlls to C# project.

My C/C++ projects is of type UnManaged and it is not a COM Project. I have seen few articles after from MSDN and tried:

[DllImport("user32.dll", EntryPoint="MessageBoxA")]

But I am not sure Where should I place the user32.dll or my.dll. Do I need to 开发者_开发问答place my dll in GAC or in some other physical folder.

If that is going to be a physical folder then , Don't I need to use either relative or absolute path?

Also read few articles talking about porting the C++ dlls using InterOp but not quite sure how to start with.


Please don't put your own dll's in C:\Windows\system32. If you're going to use part of Windows, like user32.dll, you don't put it anywhere, it's already there and will be found at runtime because C:\Windows\system32 is on the path. If you're going to use your own DLL, put it in the bin or bin\Debug or whatever folder, right next to your exe. This is most easily accomplished by adding it to the project so it will copy into the output directory when you build, but you could have an MSI or whatever. If it's used by multiple applications you have to decide if you want them all to start using the new one when it's updated, or to sit happy with their existing copies. That can be a complicated question and you have enough going on getting it working for one app, right?

As for Entry Point, it's the name of the function inside the DLL. If you're using the same name in your managed code, you can leave it out. It lets you map a DLL function name that you may find complicated into a simpler name you're using in your managed code.


You can place it in your application bin folder.

0

精彩评论

暂无评论...
验证码 换一张
取 消