Home All Groups Group Topic Archive Search About

Pass string from vb.net 2005 to c dll

Author
5 May 2006 5:57 PM
Bob Simoneau
I have a function call to a C DLL which takes a string as a parameter, and
modified the string.  I keep getting the following error.  I beleive I have
to marshal the string, but I am unsure how to do that.

Error;
Attempted to read or write protected memory. This is often an indication
that other memory is corrupt.

Author
5 May 2006 6:12 PM
Mythran
"Bob Simoneau" <bobsimoneau@newsgroups.nospam> wrote in message
news:%23WuVe1GcGHA.3956@TK2MSFTNGP05.phx.gbl...
>I have a function call to a C DLL which takes a string as a parameter, and
>modified the string.  I keep getting the following error.  I beleive I have
>to marshal the string, but I am unsure how to do that.
>
> Error;
> Attempted to read or write protected memory. This is often an indication
> that other memory is corrupt.
>

Instead of passing a string, try passing a StringBuilder (and defining the
function to pass a StringBuilder as well).

HTH,
Mythran
Author
5 May 2006 6:55 PM
Herfried K. Wagner [MVP]
"Bob Simoneau" <bobsimoneau@newsgroups.nospam> schrieb:
>I have a function call to a C DLL which takes a string as a parameter, and
>modified the string.  I keep getting the following error.  I beleive I have
>to marshal the string, but I am unsure how to do that.

I suggest to post the function prototype in C and the 'Declare' or
'DllImport' you are using in VB.NET.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
5 May 2006 8:47 PM
vbnetdev
Also try putting a copy of the dll in the system32 directory of your system.

--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com



Show quoteHide quote
"Bob Simoneau" <bobsimoneau@newsgroups.nospam> wrote in message
news:%23WuVe1GcGHA.3956@TK2MSFTNGP05.phx.gbl...
>I have a function call to a C DLL which takes a string as a parameter, and
>modified the string.  I keep getting the following error.  I beleive I have
>to marshal the string, but I am unsure how to do that.
>
> Error;
> Attempted to read or write protected memory. This is often an indication
> that other memory is corrupt.
>