473,320 Members | 1,707 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.

Translating char variable type from C++

I'm trying (in VB2005) to interact with a third-party DLL written (I
think) in C++.

One of the functions requires me to pass a structure consisting
solely of char types according to the DLL documentation, but AIUI in
C++ this will be single byte values not unicode as in .Net. Each
variable element of the srtucture will assume a simple integer value
of 0, 1, 2 or 3 - in other words digits only and no other characters.

I'm thinking that in VB2005 I should make the structure of byte type
elements. Anyone care to confirm/correct me please?
May 21 '07 #1
6 2006
On 21 mayo, 13:19, John Dann <n...@prodata.co.ukwrote:
I'm trying (in VB2005) to interact with a third-party DLL written (I
think) in C++.

One of the functions requires me to pass a structure consisting
solely of char types according to the DLL documentation, but AIUI in
C++ this will be single byte values not unicode as in .Net. Each
variable element of the srtucture will assume a simple integer value
of 0, 1, 2 or 3 - in other words digits only and no other characters.

I'm thinking that in VB2005 I should make the structure of byte type
elements. Anyone care to confirm/correct me please?
Hi there,

Arrays and structures in c++ are always By Reference Parameters (I
Think). However, I dont understand very well what you are trying to do.

May 21 '07 #2
On 21 May 2007 15:22:15 -0700, diAb0Lo <ga********@gmail.comwrote:
>Arrays and structures in c++ are always By Reference Parameters (I
Think). However, I dont understand very well what you are trying to do.
OK, let me try and explain in a little more detail:

I'm trying (in VB2005) to interact with a third-party DLL written (I
think) in C++, but almost certainly not in a .Net version of the
language. Therefore I'm having to use COM Interop Services. I can call
several of the functions in the DLL successfully so I know that my
approach is working OK in general.

However there's one particular DLL function that is refusing to work
correctly. This is a function that requires a structure passed to it.
The structure definition (from the C/C++ documentation) is:

struct MyStructure
{
char parA;
char parB;
char parC;
}

where parA, B, C etc seem to take simple integer values like 0, 1, 2,
3 (even though they're typed as char).

I'm trying to simulate this structure in VB2005 as in:

Public Structure MyDotNetStructure
Dim parA as Byte
Dim parB as Byte
Dim parC as Byte
End Structure

and then setting the values for the structure elements like:

MyDotNetStructure.parA=Asc("0")

(Using the Asc() function to simulate the value that the C++ char
might have, was my thinking.)

then calling the DLL function by

Dim Response as short = DLLName.MyFunction(ByRef MyDotNetStructure)

(MyFunction is declared as a shared function in a class in my project
called DLLName that imports the InterOpServices.)

But I keep getting an 'invalid data' response from the function. I
presume that I haven't got the values or type of the structure right
but I'm not sure what to try next - there are quite a few permutations
of ByRef/ByVal, byte values etc etc. I was hoping someone might be a
bit more familiar with how to code this sort of communication.

Anyone please?
May 22 '07 #3
John Dann wrote:
where parA, B, C etc seem to take simple integer values like 0, 1, 2,
3 (even though they're typed as char).
MyDotNetStructure.parA=Asc("0")
But I keep getting an 'invalid data' response from the function.
Asc("0") is 48 - is that a valid number to send it?

If you want to set it to a number, set it to a number:
MyDotNetStructure.parA = 0

HTH

Andrew
May 22 '07 #4
On Tue, 22 May 2007 09:05:40 +0100, "Andrew Morton"
<ak*@in-press.co.uk.invalidwrote:
>Asc("0") is 48 - is that a valid number to send it?
Yes I think that's the problem - thanks. This was actually how I had
it originally, but it wasn't working so I started to wonder whether
char wasn't more like a string type and hence added the Asc()
conversion. Possibly what stopped it working originally was that the
structure was being passed ByVal and not ByRef (as per diAb0Lo's
suggestion). But when I changed to ByRef I didn't then remove the
Asc() conversion again.
May 22 '07 #5
On 22 mayo, 03:42, John Dann <n...@prodata.co.ukwrote:
On 21 May 2007 15:22:15 -0700, diAb0Lo <garis.s...@gmail.comwrote:
Arrays and structures in c++ are always By Reference Parameters (I
Think). However, I dont understand very well what you are trying to do.

OK, let me try and explain in a little more detail:

I'm trying (in VB2005) to interact with a third-party DLL written (I
think) in C++, but almost certainly not in a .Net version of the
language. Therefore I'm having to use COM Interop Services. I can call
several of the functions in the DLL successfully so I know that my
approach is working OK in general.

However there's one particular DLL function that is refusing to work
correctly. This is a function that requires a structure passed to it.
The structure definition (from the C/C++ documentation) is:

struct MyStructure
{
char parA;
char parB;
char parC;

}

where parA, B, C etc seem to take simple integer values like 0, 1, 2,
3 (even though they're typed as char).

I'm trying to simulate this structure in VB2005 as in:

Public Structure MyDotNetStructure
Dim parA as Byte
Dim parB as Byte
Dim parC as Byte
End Structure

and then setting the values for the structure elements like:

MyDotNetStructure.parA=Asc("0")

(Using the Asc() function to simulate the value that the C++ char
might have, was my thinking.)

then calling the DLL function by

Dim Response as short = DLLName.MyFunction(ByRef MyDotNetStructure)

(MyFunction is declared as a shared function in a class in my project
called DLLName that imports the InterOpServices.)

But I keep getting an 'invalid data' response from the function. I
presume that I haven't got the values or type of the structure right
but I'm not sure what to try next - there are quite a few permutations
of ByRef/ByVal, byte values etc etc. I was hoping someone might be a
bit more familiar with how to code this sort of communication.

Anyone please?
Yet, I dont understand what your problem is. See, I did this and
worked ok:

Public Structure MyDotNetStructure
Dim parA As Byte
Dim parB As Byte
Dim parC As Byte
End Structure

Dim mySt as new MyDotNetStructure
mySt.parA = Asc("0")

At least parA is set to 48.

May 22 '07 #6
On 22 mayo, 03:42, John Dann <n...@prodata.co.ukwrote:
On 21 May 2007 15:22:15 -0700, diAb0Lo <garis.s...@gmail.comwrote:
Arrays and structures in c++ are always By Reference Parameters (I
Think). However, I dont understand very well what you are trying to do.

OK, let me try and explain in a little more detail:

I'm trying (in VB2005) to interact with a third-party DLL written (I
think) in C++, but almost certainly not in a .Net version of the
language. Therefore I'm having to use COM Interop Services. I can call
several of the functions in the DLL successfully so I know that my
approach is working OK in general.

However there's one particular DLL function that is refusing to work
correctly. This is a function that requires a structure passed to it.
The structure definition (from the C/C++ documentation) is:

struct MyStructure
{
char parA;
char parB;
char parC;

}

where parA, B, C etc seem to take simple integer values like 0, 1, 2,
3 (even though they're typed as char).

I'm trying to simulate this structure in VB2005 as in:

Public Structure MyDotNetStructure
Dim parA as Byte
Dim parB as Byte
Dim parC as Byte
End Structure

and then setting the values for the structure elements like:

MyDotNetStructure.parA=Asc("0")

(Using the Asc() function to simulate the value that the C++ char
might have, was my thinking.)

then calling the DLL function by

Dim Response as short = DLLName.MyFunction(ByRef MyDotNetStructure)

(MyFunction is declared as a shared function in a class in my project
called DLLName that imports the InterOpServices.)

But I keep getting an 'invalid data' response from the function. I
presume that I haven't got the values or type of the structure right
but I'm not sure what to try next - there are quite a few permutations
of ByRef/ByVal, byte values etc etc. I was hoping someone might be a
bit more familiar with how to code this sort of communication.

Anyone please?
Yet, I dont understand what your problem is. See, I did this and
worked ok:

Public Structure MyDotNetStructure
Dim parA As Byte
Dim parB As Byte
Dim parC As Byte
End Structure

Dim mySt as new MyDotNetStructure
mySt.parA = Asc("0")

At least parA is set to 48.

May 22 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Julian Maisano | last post by:
Can anybody help me to translate the following lines to pascal(delphi)? Let me explain what I'm looking for: int i = 1; {In this line, an integer variable which is called "i" is declared and...
28
by: Merrill & Michele | last post by:
#include <stdio.h> #include <string.h> #include <stdlib.h> int main(void){ char *p; p=malloc(4); strcpy(p, "tja"); printf("%s\n", p); free(p); return 0;
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
31
by: Hans | last post by:
Hello, Why all C/C++ guys write: const char* str = "Hello"; or const char str = "Hello";
33
by: baumann.Pan | last post by:
hi all, i want to get the address of buf, which defined as char buf = "abcde"; so can call strsep(address of buf, pointer to token);
17
by: mdh | last post by:
In trying to understand the issue, I wrote this; #include <stdio.h> void f_output(char arg1, int limit); int main () { f(); return 0; }
0
by: maheshmohta | last post by:
Background Often while remodeling legacy application, one of the important tasks for the architects is to have an optimum usage of storage capabilities of database. Most of the legacy applications...
3
by: stax76 | last post by:
Hello, can anybody tell me what it would look like in C++? byte bRawData = new byte; int pRawData = buffer.ToInt32() + Marshal.SizeOf(typeof(RAWINPUT)) + 1; // buffer is of type IntPtr...
14
by: rtillmore | last post by:
Hello, I did a quick google search and nothing that was returned is quite what I am looking for. I have a 200 character hexadecimal string that I need to convert into a 100 character string. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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: 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...
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)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.