Click here to Skip to main content
15,893,487 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to raise Mouse click event Pin
Curtis Schlak.13-Dec-05 10:51
Curtis Schlak.13-Dec-05 10:51 
AnswerRe: How to raise Mouse click event Pin
MarcelErz13-Dec-05 22:55
MarcelErz13-Dec-05 22:55 
AnswerRe: How to raise Mouse click event Pin
bloo2k13-Dec-05 22:56
bloo2k13-Dec-05 22:56 
Questionwhen text is longer than its textbox Pin
melanieab13-Dec-05 9:24
melanieab13-Dec-05 9:24 
AnswerRe: when text is longer than its textbox Pin
Curtis Schlak.13-Dec-05 10:55
Curtis Schlak.13-Dec-05 10:55 
GeneralRe: when text is longer than its textbox Pin
melanieab14-Dec-05 3:27
melanieab14-Dec-05 3:27 
GeneralRe: when text is longer than its textbox Pin
Curtis Schlak.14-Dec-05 4:35
Curtis Schlak.14-Dec-05 4:35 
QuestionHow do I free memory allocated inside unmanaged DLL? Pin
Koushik Biswas13-Dec-05 9:14
Koushik Biswas13-Dec-05 9:14 
OK - I want to keep the question short & quick. Please help me.

Step 1: I write an unmanaged DLL in C++. Here is the exported function:

SAMPLEDLL_API void StringAsOUT_AllocatedInDll( char ** szParam )
{
*szParam = new char [ 128 ];
strcpy( *szParam, "Please free my memory after using me!" );
}

Step 2: I write a C# managed EXE to use this DLL

class Imports
{
[DllImport("SampleDLL.dll")]
public static extern void StringAsOUT_AllocatedInDll( ref int szParam );
...
}

...
Imports impObj = new Imports();
int iAddressOfANSIString = 0;
impObj.StringAsOUT_AllocatedInDll( ref iAddressOfANSIString );
string strOUTPUTFromUnmanagedDll = Marshal.PtrToStringAnsi( ( IntPtr ) iAddressOfANSIString );
Console.WriteLine( "Value of strOUTPUTFromUnmanagedDll = {0}", strOUTPUTFromUnmanagedDll );
...

Question: The code works. It does give console output "Value of strOUTPUTFromUnmanagedDll = Please free my memory after using me!"

But isn't there a memory leak? How do I free the memory allocated by new[] inside the unmanaged DLL? All the Marshal class helps artciles always refer to how to free an unmanaged memory block when it is allocated from .NET code. But here it is allocated by unamanaged code. If anybody can please help me with this, I will be grateful.

Thank you!

Koushik Biswas
QuestionCan not add rows into Datset using Merge() Pin
Roman Muntyanu13-Dec-05 8:52
Roman Muntyanu13-Dec-05 8:52 
AnswerRe: Can not add rows into Datset using Merge() Pin
Drew McGhie13-Dec-05 9:19
Drew McGhie13-Dec-05 9:19 
GeneralRe: Can not add rows into Datset using Merge() Pin
Roman Muntyanu13-Dec-05 9:58
Roman Muntyanu13-Dec-05 9:58 
QuestionX in the top right corner of the form Pin
zaboboa13-Dec-05 8:17
zaboboa13-Dec-05 8:17 
AnswerRe: X in the top right corner of the form Pin
Dan Neely13-Dec-05 9:21
Dan Neely13-Dec-05 9:21 
QuestionA question about Reflection Pin
torrentmoon13-Dec-05 8:11
torrentmoon13-Dec-05 8:11 
AnswerRe: A question about Reflection Pin
Curtis Schlak.13-Dec-05 10:59
Curtis Schlak.13-Dec-05 10:59 
Questionn-tier (Typed dataset) Pin
fmardani13-Dec-05 6:38
fmardani13-Dec-05 6:38 
QuestionSoftware protection Pin
mirano13-Dec-05 6:34
mirano13-Dec-05 6:34 
AnswerRe: Software protection Pin
Robert Rohde13-Dec-05 8:07
Robert Rohde13-Dec-05 8:07 
AnswerRe: Software protection Pin
mcljava15-Dec-05 5:51
mcljava15-Dec-05 5:51 
QuestionSmooth edge panel and button Pin
VPMahank13-Dec-05 6:16
VPMahank13-Dec-05 6:16 
AnswerRe: Smooth edge panel and button Pin
Robert Rohde13-Dec-05 8:10
Robert Rohde13-Dec-05 8:10 
GeneralRe: Smooth edge panel and button Pin
VPMahank13-Dec-05 8:58
VPMahank13-Dec-05 8:58 
QuestionTransparent Color in Asp .Net C# Pin
Vodstok13-Dec-05 5:46
Vodstok13-Dec-05 5:46 
GeneralRe: Transparent Color in Asp .Net C# Pin
Guffa13-Dec-05 7:27
Guffa13-Dec-05 7:27 
GeneralRe: Transparent Color in Asp .Net C# Pin
Vodstok13-Dec-05 7:30
Vodstok13-Dec-05 7:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.