在c ++中使用带有托管c ++和c#的AfxBeginThread [英] Using AfxBeginThread in c++ with managed c++ and c#
问题描述
我有一个ac#project,Managed c ++和Native c ++的解决方案。
我在本机c ++中调用了一个函数,它有
AfxBeginThread(
Start_new_child_process,
(LPVOID)设置,
NULL,
0 ,
0 ,
NULL
);
当我尝试通过托管c ++项目从C#项目调用本机c ++函数时,我收到此错误:
Dubug Assertation失败!< br $>
程序:... GUI.vshost.exe
文件:fdd\vctools \\ \\ vc7libs\ship\atlmfc\afxwin1.inl
行:21
使用只有C ++ Native项目的相同代码工作正常!
任何想法如何解决问题?
谢谢
我不要为通常从C#到C做任何事情++(I只是停留100%C ++)。通常调试断言与句柄和东西有关。
查看该文件,在第21行我看到以下
AFXWIN_INLINE HINSTANCE AFXAPI AfxGetInstanceHandle()
{ASSERT(afxCurrentInstanceHandle!= NULL);
返回afxCurrentInstanceHandle; }
断言是你的线程没有当前实例句柄。在我看来,您需要将C#应用程序的实例句柄设置为该线程,并看看它是如何进行的。我不明白如何做到这一点,因为我不是C#人。
我相信这必须位于链接的DLL项目中作为多线程DLL(/ MD [d])
我希望我能提供更多帮助
I have a solution with a c# project, Managed c++ and Native c++.
I call a function in the native c++ which has
AfxBeginThread(
Start_new_child_process,
(LPVOID)Setting,
NULL,
0,
0,
NULL
);
when I try calling the native c++ function from the C# project via the Managed c++ project i get this error:
Dubug Assertation failed!
Program: ...GUI.vshost.exe
File: f"dd\vctools\vc7libs\ship\atlmfc\afxwin1.inl
Line:21
Using the same code with only the C++ Native project works fine!
Any idea how to solve the problem?
thanks
I don''t normally do anything from C# to C++ (I just stay 100% C++). Usually debug assertions in that have to do with handles and stuff.
Looking at that file, on line 21 I see the following
AFXWIN_INLINE HINSTANCE AFXAPI AfxGetInstanceHandle() { ASSERT(afxCurrentInstanceHandle != NULL); return afxCurrentInstanceHandle; }
The assertion is that your thread has no current instance handle. It appears to me that you need to set the instance handle of your C# application to the thread and see how that goes. It is not obvious to me how to do that since I''m not a C# person.
I believe that this must be located in a DLL project that is linked as multithreaded DLL (/MD[d])
I wish I could be more helpful
这篇关于在c ++中使用带有托管c ++和c#的AfxBeginThread的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!