Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C++/CLI C#
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
Posted 17-Apr-13 1:34am
Edited 17-Apr-13 7:40am
v2
Comments
ThePhantomUpvoter at 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 at 17-Apr-13 17:03pm
   
Agree. Besides, there is no "managed C++", please see below.
—SA
Sergey Alexandrovich Kryukov at 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 at 18-Apr-13 2:59am
   
sorry for the missunderstanding - I am using C++/CLI

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100