P/Invove and ByRef Strings

  • Thread starter Thread starter KRoy
  • Start date Start date
K

KRoy

What is the trick to sending strings to an API when the
function you are calling wants the data ByRef.

For example the CryptEncrypt in the CryptoAPI needs you to
send it the data you want to encrypt, and then it returns
it in the same variable (ie ByRef). But it actually only
wants a pointer to the data. In VB6 passing it ByVal,
even though it was defined as ByRef worked just great. In
vb.net ByVal is no longer supported. When I send it, I
get a system exception object reference not.
 
For example the CryptEncrypt in the CryptoAPI needs you to
send it the data you want to encrypt, and then it returns
it in the same variable (ie ByRef). But it actually only
wants a pointer to the data.

Since the function works with binary data and not necessarily text,
I'd use a byte array rather than a string for that parameter.

In VB6 passing it ByVal,
even though it was defined as ByRef worked just great.

That should still work.

In vb.net ByVal is no longer supported.

Sure it is.

When I send it, I
get a system exception object reference not.

Better post your code, it's hard to say why it fails without seeing
it.



Mattias
 
Back
Top