c#调用c ++函数 [英] c# calls c++ function
问题描述
我尝试使用
I have try to use
[DllImport(" kernel32.dll")]
$
public static extern IntPtr GetProcAddress(IntPtr hModule) ,string procedureName);
[DllImport("kernel32.dll")]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
和 Marshal.GetDelegateForFunctionPointer
and Marshal.GetDelegateForFunctionPointer
从c#project中的c ++库中获取c ++函数指针。
to get the c++ function pointer from c++ library in c# project.
一切似乎都没问题,我可以在GetProcAddress和Marshal.GetDelegateForFunctionPointer中获得非零的IntPtr。
Everything seems okay, i can get non-zero IntPtr in both GetProcAddress and Marshal.GetDelegateForFunctionPointer.
然而,当我调用该函数时,它会返回IntPtr .Zero。
However, when i invoke the function, it would return IntPtr.Zero.
当我在Visual Studio Hosting中调试时,该函数成功调用而没有任何问题。但是,当我在没有Visual Studio托管的构建之后运行程序时,该函数返回IntPtr.Zero。
When i debugging in Visual Studio Hosting, the function invokes successfully without any problems. However, when i run the program after build without Visual studio hosting, the function return IntPtr.Zero.
任何人都可以帮忙??
Any one can help ??
推荐答案
但为什么函数在visual下成功调用在编译版本中托管工作室??
But why the function invokes successfully under visual studio hosting whilst in compiled version??
这篇关于c#调用c ++函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!