P/Invove and ByRef Strings

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.
 
M

Mattias Sjögren

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top