Click here to Skip to main content
15,891,698 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I have a solution with a c# project, Managed c++ and Native c++.

I call a function in the native c++ which has

C++
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
Posted
Updated 17-Apr-13 6:40am
v2
Comments
[no name] 17-Apr-13 8:25am    
"Any idea how to solve the problem", sure, it's called debugging. You have not provided any information that would enable anyone to tell you what the problem is with your code.
Sergey Alexandrovich Kryukov 17-Apr-13 17:03pm    
Agree. Besides, there is no "managed C++", please see below.
—SA
Sergey Alexandrovich Kryukov 17-Apr-13 17:03pm    
Just a note: there is no such thing as "managed C++"; in the near past, it was a jargon name for "Managed C++ extensions". This product is discontinued and superseded with C++/CLI, without backward compatibility with "managed extensions", so you don't want to use it anymore. Use C++/CLI.
—SA
spaarvap 18-Apr-13 2:59am    
sorry for the missunderstanding - I am using C++/CLI

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900