|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
memeory release from un managed codeNeed your help, >From our vb.net web service we are calling a unmanaged C++ win32 dll function. The dll function takes a string (consists of huge data)parameter byref. Below code sample. Do we have to take care in .net for the memory allocated in the c++ dll (SysAllocStringByteLen ?). Or does .net on exiting handles this. How does we release the memory allocated.. Please.. Thanks saish (Developer) Vb.net code: --------------- Declare Function fnstrOutput Lib "C:\net\dlls\xmlref.dll" _ Alias "STR_OUTPUT" (ByRef outString As String) As Integer ... ... <WebMethod()> _ Public Function Teststring() As String Dim outstr as string rc = fnstrOutput(outstr) return "return : " + ctype(rc,string) End Function C++ win32 dll code: --------------------------- extern "C" { extern int WINAPI fnOutput(BSTR *poutputDoc); } //******* Test passing Output string ByRef ***************** int WINAPI fnOutput(BSTR *poutDoc) { SysFreeString(*poutDoc); // SysAllocStringByteLen() function takes ANSI string and returns // a BSTR. // poutXML is a DOMDOCUMENTPTR type ... *poutDoc = SysAllocStringByteLen(poutXML->xml, poutXML->xml.length() -1); return 90; } Hi,
The framework's garbage collector should dispose of the string for you. Ken --------------- Show quoteHide quote "sanu" <sa***@eircom.net> wrote in message news:1137669305.558396.304310@g44g2000cwa.googlegroups.com... > Hi, > > Need your help, > >>From our vb.net web service we are calling a unmanaged C++ win32 dll > function. The dll function takes a string (consists of huge data) > parameter byref. Below code sample. > > Do we have to take care in .net for the memory allocated in the c++ dll > (SysAllocStringByteLen ?). Or does .net on exiting handles this. How > does we release the memory allocated.. Please.. > > Thanks > saish (Developer) > > > Vb.net code: > --------------- > Declare Function fnstrOutput Lib "C:\net\dlls\xmlref.dll" _ > Alias "STR_OUTPUT" (ByRef outString As String) As Integer > .. > .. > > <WebMethod()> _ > Public Function Teststring() As String > > Dim outstr as string > > rc = fnstrOutput(outstr) > > return "return : " + ctype(rc,string) > > End Function > > > C++ win32 dll code: > --------------------------- > extern "C" > { > extern int WINAPI fnOutput(BSTR *poutputDoc); > } > > //******* Test passing Output string ByRef ***************** > > int WINAPI fnOutput(BSTR *poutDoc) > { > > > SysFreeString(*poutDoc); > > // SysAllocStringByteLen() function takes ANSI string and returns > > // a BSTR. > // poutXML is a DOMDOCUMENTPTR type ... > > *poutDoc = SysAllocStringByteLen(poutXML->xml, poutXML->xml.length() > -1); > > return 90; > } > Hi Ken,
Thanks for your reply. I had been reading the various forums saying we have to release the memory ( using SysFreeString), which are created by un-managed code (in my case win32 c++ dll). But was somewhat confused how this was possible. Please excuse my lack of knowledge ..But how does the (garbage collector ?) vb.net program releases (de-allocates) the memory allocated by the un managed code. Thanks saish Ken Tucker [MVP] wrote: Show quoteHide quote > Hi, > > The framework's garbage collector should dispose of the string for > you. > > Ken > --------------- > "sanu" <sa***@eircom.net> wrote in message > news:1137669305.558396.304310@g44g2000cwa.googlegroups.com... > > Hi, > > > > Need your help, > > > >>From our vb.net web service we are calling a unmanaged C++ win32 dll > > function. The dll function takes a string (consists of huge data) > > parameter byref. Below code sample. > > > > Do we have to take care in .net for the memory allocated in the c++ dll > > (SysAllocStringByteLen ?). Or does .net on exiting handles this. How > > does we release the memory allocated.. Please.. > > > > Thanks > > saish (Developer) > > > > > > Vb.net code: > > --------------- > > Declare Function fnstrOutput Lib "C:\net\dlls\xmlref.dll" _ > > Alias "STR_OUTPUT" (ByRef outString As String) As Integer > > .. > > .. > > > > <WebMethod()> _ > > Public Function Teststring() As String > > > > Dim outstr as string > > > > rc = fnstrOutput(outstr) > > > > return "return : " + ctype(rc,string) > > > > End Function > > > > > > C++ win32 dll code: > > --------------------------- > > extern "C" > > { > > extern int WINAPI fnOutput(BSTR *poutputDoc); > > } > > > > //******* Test passing Output string ByRef ***************** > > > > int WINAPI fnOutput(BSTR *poutDoc) > > { > > > > > > SysFreeString(*poutDoc); > > > > // SysAllocStringByteLen() function takes ANSI string and returns > > > > // a BSTR. > > // poutXML is a DOMDOCUMENTPTR type ... > > > > *poutDoc = SysAllocStringByteLen(poutXML->xml, poutXML->xml.length() > > -1); > > > > return 90; > > } > >
Insert data in VB.Net
Copying one project to another create user and add to admin group under local system Run code under diffrent user remove blank strings in arraylist Can I do this on One line of code? How to insert a page break in multi-page document? Threads Question - updating UI system.data.oledb Tray icon to change IP Gateway? |
|||||||||||||||||||||||