开发者

C# dll that can be pinvoked?

Question: Is it possible to write a C# dll that can be pinvoked ?

I want to write a replacement library for the WinAPI calls WritePrivateProfileString etc. for reading and wr开发者_JAVA百科iting ini files.

Is it possible to export a function, e.g. 'WritePrivateProfileString', implemented in C# so one can pinvoke the dll with DllImport ?

I want to replace the native dll with a managed dll, so the managed dll gets called by the pinvoke call (instead of the native dll, when the managed dll is in the bin directory).


Contrary to popular belief, this is possible. (note that you'll need to modify the calling application to import from your DLL)
See here.

However, in your case, it's not necessarily a good idea.
Why don't you change the extern declarations to normal methods that call your replacements?


This is not easy, but it can be done with the use of a few “hacks”

However COM may be a better option for you, as it is easy to export a com object from C# and to use com objects from VB6. Then change the extern declarations to normal methods that call you’re your com objects.


Try using Mono Cecil to change the third-party program's extern methods to methods that call your DLL (without P/Invoke).

Reflector will help here.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜