Click here to Skip to main content
13,045,790 members (47,028 online)
Rate this:
Please Sign up or sign in to vote.
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


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


Using the same code with only the C++ Native project works fine!
Any idea how to solve the problem?

Posted 17-Apr-13 0:34am
Updated 17-Apr-13 6:40am
ThePhantomUpvoter 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.
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.
spaarvap 18-Apr-13 2:59am
sorry for the missunderstanding - I am using C++/CLI

1 solution

Rate this: bad
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

	{ 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

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

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2017
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