Click here to Skip to main content
15,915,719 members
Home / Discussions / C#
   

C#

 
GeneralRe: ASPX using C# : Exception Details: System.Web.HttpException: A page can have only one server-side Form tag. Pin
jmfekete15-Dec-05 8:06
jmfekete15-Dec-05 8:06 
GeneralRe: ASPX using C# : Exception Details: System.Web.HttpException: A page can have only one server-side Form tag. Pin
enjoycrack15-Dec-05 8:09
enjoycrack15-Dec-05 8:09 
GeneralRe: ASPX using C# : Exception Details: System.Web.HttpException: A page can have only one server-side Form tag. Pin
jmfekete15-Dec-05 8:25
jmfekete15-Dec-05 8:25 
QuestionComposite Pattern and Generics Pin
RogerRabbit7815-Dec-05 7:20
RogerRabbit7815-Dec-05 7:20 
QuestionASPX using C# : System.InvalidCastException: Specified cast is not valid Pin
jmfekete15-Dec-05 6:57
jmfekete15-Dec-05 6:57 
AnswerRe: ASPX using C# : System.InvalidCastException: Specified cast is not valid Pin
enjoycrack15-Dec-05 7:00
enjoycrack15-Dec-05 7:00 
GeneralRe: ASPX using C# : System.InvalidCastException: Specified cast is not valid Pin
jmfekete15-Dec-05 7:25
jmfekete15-Dec-05 7:25 
GeneralRe: ASPX using C# : System.InvalidCastException: Specified cast is not valid Pin
jmfekete15-Dec-05 7:30
jmfekete15-Dec-05 7:30 
GeneralRe: ASPX using C# : System.InvalidCastException: Specified cast is not valid Pin
enjoycrack15-Dec-05 7:52
enjoycrack15-Dec-05 7:52 
AnswerRe: ASPX using C# : System.InvalidCastException: Specified cast is not valid Pin
chinky singh15-Dec-05 7:22
chinky singh15-Dec-05 7:22 
GeneralRe: ASPX using C# : System.InvalidCastException: Specified cast is not valid Pin
jmfekete15-Dec-05 7:29
jmfekete15-Dec-05 7:29 
QuestionA Static class Serialization problem Pin
HolyGrandFather15-Dec-05 6:45
HolyGrandFather15-Dec-05 6:45 
AnswerRe: A Static class Serialization problem Pin
Guffa15-Dec-05 11:39
Guffa15-Dec-05 11:39 
GeneralRe: A Static class Serialization problem Pin
HolyGrandFather16-Dec-05 8:59
HolyGrandFather16-Dec-05 8:59 
AnswerRe: A Static class Serialization problem Pin
Guffa18-Dec-05 0:48
Guffa18-Dec-05 0:48 
GeneralRe: A Static class Serialization problem Pin
HolyGrandFather18-Dec-05 5:27
HolyGrandFather18-Dec-05 5:27 
AnswerRe: A Static class Serialization problem Pin
Guffa18-Dec-05 22:51
Guffa18-Dec-05 22:51 
GeneralRe: A Static class Serialization problem Pin
HolyGrandFather19-Dec-05 4:50
HolyGrandFather19-Dec-05 4:50 
QuestionBrowser closing event Pin
chinky singh15-Dec-05 5:51
chinky singh15-Dec-05 5:51 
AnswerRe: Browser closing event Pin
albCode15-Dec-05 5:54
albCode15-Dec-05 5:54 
GeneralRe: Browser closing event Pin
chinky singh15-Dec-05 6:12
chinky singh15-Dec-05 6:12 
AnswerRe: Browser closing event Pin
Guffa15-Dec-05 11:54
Guffa15-Dec-05 11:54 
QuestionFree memory allocated in unmanaged DLL from C# Pin
Koushik Biswas15-Dec-05 5:50
Koushik Biswas15-Dec-05 5:50 
I will ask the question with a 2 step introduction... Please help me.

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

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


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

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


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


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!
AnswerRe: Free memory allocated in unmanaged DLL from C# Pin
albCode15-Dec-05 5:56
albCode15-Dec-05 5:56 
QuestionThanks, but this is still not answered... Pin
Koushik Biswas15-Dec-05 6:04
Koushik Biswas15-Dec-05 6:04 

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.