Memory error with funcs that return char*

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I have an odd error comming up that does not seem to actually cause a
problem (everything seems to work fine) but it concerns me.

Error:
----------------------------------------
HEAP[appname.exe]: Invalid Address specified to RtlFreeHeap( 00170000,
10015988 )
Windows has triggered a breakpoint in appname.exe.

This may be due to a corruption of the heap, and indicates a bug in
appname.exe or any of the DLLs it has loaded.

The output window may have more diagnostic information
----------------------------------------

I have a Win32 C application that loads up the .NET CLR via
CorBindToRuntimeEx(). I creates an instance of a C# class that uses
DllImport statements to link back into a Win32 C DLL that has several
helper functions.

The only time that this error comes up is when I run in debug mode AND when
I have VS2005 startup the Win32 appplication. If I have VS2005 startup the
C# DLL and tell it to launch (ie. Start External Program) the Win32
application it works fine. It only seems to show up when I have a helper
(Win32 C DLL) function that returns a char*. If they return int, float,
etc. I do not get this error.

Is there something special with char*'s being returned from C code when
called via C# and DllImport?

Sorry for the lack of info - it is one of those hard to describe setups!

Here is what it looks like from a flow standpoint:

(Win32 C console app)
-> (loads up .NET CLR)
-> (creates instance of class within C# DLL)
-> (C# class makes calls to Win32 C DLL)

Here is a sample function I am using that just returns a hard coded string:

Win32 C DLL function def (cfile.dll):
extern "C" __declspec(dllexport) char* __stdcall TEST( )
{
return "hello world from TEST() function";
}

C# DllImport:
[DllImport("cfile.dll")]
public static extern String TEST();

Not sure what else to say... cannot really post sample projects so
hopefully someone can help without 'em!

Thanks.
.



Relevant Pages

  • Re: Debugging JNI shared libraries
    ... >compiles OK on Win32 when I have teh requisite stuff installed and I'm ... >DllMain gets called, attach to the dll? ... code as far as the debugger is concerned). ...
    (comp.programming)
  • Re: Exiting process
    ... if you still want to use the original method, don't use a DLL, ... Also this is only valid for win32 apps with kernel32.dll mapped into their ... > window. ...
    (microsoft.public.vc.language)
  • Re: wh_callwndProc hook problem
    ... win32 dll. ... If you use win32 api DllMain, merge my codes of DllMain with that of yours. ... link but when i search in google groups i find..how this thread is transfered ...
    (microsoft.public.vc.language)
  • Re: C coding guidelines
    ... /your/ code's entry point, then it isn't what we're talking about - ... but I'm talking specifically about Win32 GUI. ... The REAL entry point for a Win32 GUI program is WinMainCRTStartup. ... link with to produce the DLL. ...
    (comp.lang.c)
  • Re: Can VB.Net talk to C/C++ code?
    ... platform invoke with <DLLImport>, once you have used that attribute, you ... can call the method as if it is a .NET method. ... Is it a DLL with exported C++ functions. ... public members. ...
    (microsoft.public.dotnet.faqs)