473,320 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

P/Invove and ByRef Strings

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
2 1106
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andy Read | last post by:
Dear all, I thought I understood passing parameters ByVal and ByRef but I clearly don't! If I define a simple class of: Public Class Person Public Name as String Public Age as Integer End...
8
by: Sandy | last post by:
Hello! Help!!!! I have ten zillion books that attempt to describe the difference between ByVal and ByRef and none of them are clear to me. I have gathered that ByVal makes a copy and ByRef...
10
by: Logico | last post by:
Hi everybody, I've tried to use the byref keyword for passing arguments to subroutines and functions in my ASP pages with VBScript, but it seems that both byref and byval are irrilevant, as simple...
7
by: Hei | last post by:
Hi, i know the difference of ByRef and ByVal, in case if use byref or byval don't affect the result which one should prefer? (less memory use, better performance ....issue) thx
4
by: Warren Sirota | last post by:
Hi, Please let me know if I am interpreting this correctly. I've done a little testing of the difference between passing parameters byVal and byRef, and the results were slightly non-intuitive,...
1
by: marfi95 | last post by:
I'm trying to call a C++ component from my vb.net app. This method has a prototype of int GetV (char *verData). I've setup a Declare statement like the following: Declare Auto Function GetV...
6
by: ari | last post by:
hey all, i have the following 2 classes: Public Class DataAccessLayer .... .... Public Sub GetRecords(ByRef ds As DataSet1) ds = New DataSet1
2
by: dougbaysal | last post by:
Good day everybody, I have a function in hand that goes like this. function ExportResult(r as integer, byRef myBStr as Object) as integer Obviously there are 2 values in and 1 out. My...
0
by: MikalE | last post by:
I’m using a third-party ActicveX component that has the following description for one of its events: They mean by this that LocationType is an array of VARIANTS (containing enumeration) When...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.