By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,569 Members | 1,630 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,569 IT Pros & Developers. It's quick & easy.

P/Invove and ByRef Strings

P: n/a
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.
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #2

P: n/a
See my last answer in your previous thread.

-Rob Teixeira [MVP]

"KRoy" <pe***@pedge.com> wrote in message
news:00****************************@phx.gbl...
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.

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.