指向C#中的函数 [英] Pointers to Functions in C#

查看:69
本文介绍了指向C#中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从C#代码注册/取消注册COM DLL,基本上是为了模仿Regsvr32.exe
。使用P / Invoke我为DLL调用LoadLibrary,当成功的时候我使用第二个参数

" DllRegisterServer"调用GetProcAddress。所以现在我有一个导出函数的地址。但是我的
找不到从C#调用这个函数的方法。我试图使用不安全的代码

声明一个指向一个甚至不能编译的函数的指针。我玩了

代表而没有结果。谢谢你的任何想法。 Kris。

I''m trying to register/unregister a COM DLL from the C# code, basically to
emulate Regsvr32.exe. Using P/Invoke I call LoadLibrary for the DLL and when
that succeeds I call GetProcAddress with the second parameter
"DllRegisterServer". So now I have an address to exported function. However I
can''t find a way to call this function from C#. I tried to use unsafe code to
declare a pointer to a function which would not even compile. I played with
delegates with not results. Thanks for any ideas. Kris.

推荐答案

感谢您的任何想法。




这里有一个解决方案:

http://www.msjogren.net/dotnet/eng/s...dynpinvoke.asp


Mattias


-

Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

请回复到新闻组。



Here''s one solution:

http://www.msjogren.net/dotnet/eng/s...dynpinvoke.asp


Mattias

--
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Mattias,

非常感谢你的帮助。您建议的解决方案很有效。我知道反思非常强大,但这令人难以置信。我有很多要学习。
学习。

问候,


Kris。


Mattias Sj ?? gren写道:
Mattias,
Thank you very much for your help. Your suggested solution works great. I
knew Reflections were very powerful but this is mind boggling. I have lots to
learn.
Regards,

Kris.

"Mattias Sj??gren" wrote:
感谢任何想法。



这是一个解决方案:

http://www.msjogren.net/ dotnet / eng / s ... dynpinvoke.asp


Mattias

-
Mattias Sj ?? gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
请仅回复新闻组。



Here''s one solution:

http://www.msjogren.net/dotnet/eng/s...dynpinvoke.asp


Mattias

--
Mattias Sj??gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.



Mattias,

这又是Kris。一个小问题,一切正常。如果我尝试

来注册依赖于另一个DLL的DLL并且这个DLL丢失了,那么从某个地方弹出

消息框。如果我从Win32调用LoadLibrary()方法,我也会得到相同的消息框。在我确认消息框

后,我从你的代码中得到一个例外,这很好。是否有任何

的方法来避免收到消息框?要先调用

的其他任何函数检查依赖列表?谢谢,

Kris。


" Mattias Sj ?? gren"写道:
Mattias,
this is Kris again. Everything works fine with one minor problem. If I try
to register DLL which depends on another DLL and this DLL is missing the
message box pops out from somewhere. I get the same message box also if I
call LoadLibrary() method from Win32. After I acknowledge the message box
then later I get an exception from your code and that''s great. Is there any
way to avoid getting the message box? Any other function to call first to
check the dependency list? Thanks,
Kris.

"Mattias Sj??gren" wrote:
感谢任何想法。



这是一个解决方案:

http://www.msjogren.net/ dotnet / eng / s ... dynpinvoke.asp


Mattias

-
Mattias Sj ?? gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
请仅回复新闻组。



Here''s one solution:

http://www.msjogren.net/dotnet/eng/s...dynpinvoke.asp


Mattias

--
Mattias Sj??gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.



这篇关于指向C#中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆