473,241 Members | 1,627 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,241 software developers and data experts.

passing an struct from vb to c dll

Hi,
I am having some problem for getting values in struct from the c dll.

I have following definition

Type MBRINFO
szMember As String * 80 ' member name array
usLevel As Integer
End Type

I am passing this struct to c dll for getting back the values filled
from the dll

Declare Function GetMemberInfo Lib "xyz" (pInfo As MBRINFO) As Long

On c side I have code as following

struct MBRINFO
{
char szMember[80];
int usLevel;
}
long GetMemberInfo(MBRINFO * info)
{
long sts = 0;
memset(info,0,sizeof(MBRINFO ));
szMember(info->szMember,"Something");
info->usLevel = 10;
return sts;
}

The definition is exported from the xyz.dll for acess.
But, when I get value back on vb side, I noticed the value for szMember
is filled with assigned value which is "Something" folloed by lot of
space characters. Can somebody help me figure out how to avoid this
issue.

Thanks,
Abhijeet

Jul 11 '06 #1
7 2952
abhijeet wrote:
Hi,
I am having some problem for getting values in struct from the c dll.
Way off topic here, try a windows specific group.

--
Ian Collins.
Jul 11 '06 #2

"abhijeet" <ab***********@gmail.comwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...

[snip]
The definition is exported from the xyz.dll for acess.
But, when I get value back on vb side, I noticed the value for szMember
is filled with assigned value which is "Something" folloed by lot of
space characters. Can somebody help me figure out how to avoid this
issue.
First of all you're offtopic. Second you dont show the VB code where you
call the dll function.
Declare Function GetMemberInfo Lib "xyz" (pInfo As MBRINFO) As Long
^^^ That is bad and wrong, and it should be:

Declare Function GetMemberInfo Lib "xyz" (ByRef pInfo As MBRINFO) As Long

When passing user defined VB types to a C dll it must be passed by reference
and not by value as you do.

//eric
Jul 11 '06 #3
adding more...

abhijeet wrote:
Hi,
I am having some problem for getting values in struct from the c dll.
Surely an off-topic but how did your dll compile with following errors?
struct MBRINFO
{
char szMember[80];
int usLevel;
}
didn't your compiler ask for ';' at the end of the structure?
long GetMemberInfo(MBRINFO * info)
{
long sts = 0;
memset(info,0,sizeof(MBRINFO ));
szMember(info->szMember,"Something");
info->usLevel = 10;
return sts;
}
szMember(info->szMember,"Something");
what is this anyway? a function?

Don't type in the thread editor. It is better to copy the code from the
compiler IDE.

-- Murali Krishna

Jul 11 '06 #4
Sorry my mistake code should read

long GetMemberInfo(MBRINFO * info)
{
long sts = 0;
memset(info,0,sizeof(MBRINFO ));
strcpy(info->szMember,"Something");
info->usLevel = 10;
return sts;
}

Anyways thank you guys for your replies.

Jul 11 '06 #5
Eric Jensen <er**@no.spam.comwrote:

"abhijeet" <ab***********@gmail.comwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
>Declare Function GetMemberInfo Lib "xyz" (pInfo As MBRINFO) As Long
^^^ That is bad and wrong, and it should be:

Declare Function GetMemberInfo Lib "xyz" (ByRef pInfo As MBRINFO) As
Long
No, his Declare is absolutely correct, as it is identical to yours.
If you omit ByRef/ByVal, you will get an implied ByRef.

regards
--
jb

(reply address in rot13, unscramble first)
Jul 11 '06 #6

google for "passing string VB dll" will get some result.
I don't remember anymore, but strings were not just strcpy, that I
know for sure.
Jul 11 '06 #7
"abhijeet" <ab***********@gmail.comwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
Hi,
I am having some problem for getting values in struct from the c dll.

I have following definition

Type MBRINFO
szMember As String * 80 ' member name array
usLevel As Integer
End Type

I am passing this struct to c dll for getting back the values filled
from the dll

Declare Function GetMemberInfo Lib "xyz" (pInfo As MBRINFO) As Long

On c side I have code as following

struct MBRINFO
{
char szMember[80];
int usLevel;
}
long GetMemberInfo(MBRINFO * info)
{
long sts = 0;
memset(info,0,sizeof(MBRINFO ));
szMember(info->szMember,"Something");
info->usLevel = 10;
return sts;
}

The definition is exported from the xyz.dll for acess.
But, when I get value back on vb side, I noticed the value for szMember
is filled with assigned value which is "Something" folloed by lot of
space characters. Can somebody help me figure out how to avoid this
issue.

Thanks,
Abhijeet
I believe your problem may do with the C style .vs. Pascal style strings. I
may be wrong, however, but perhaps vb is using the pascal style string where
the first byte is the length of the string, then the contents of the string,
where a C style string is simply null terminated.

To fix this, you should perhaps simply also add the length of the string to
the structure so you can clean it up on the Basic side. Otherwise you'll
need to research what VB is expecting it's string array to be filled with.
Jul 12 '06 #8

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

Similar topics

15
by: Dave | last post by:
I'm currently working on a small project (admitedly for my CS class) that compares the time difference between passing by value and passing by reference. I'm passing an array of 50000 int's. ...
5
by: kazack | last post by:
I am a little confused with code I am looking at. My c++ book does not go into passing a structure to a function so I pulled out a c book which does. and I do not understand the prototype verses...
9
by: Just Me | last post by:
PARAFORMAT2 is a structure that SendMessage will return stuff in. Is the "ref" correct or since only a pointer is being passed should it be by value? Suppose I was passing data rather then...
17
by: Christopher Benson-Manica | last post by:
Does the following program exhibit undefined behavior? Specifically, does passing a struct by value cause undefined behavior if that struct has as a member a pointer that has been passed to...
1
by: jconnort | last post by:
I'm trying to write a function to get the current system time, so I can use it when I need to output it to a log, below is the code I'm testing: #include "include.h" #include <stdlib.h> ...
12
by: manochavishal | last post by:
Hi, I am having strange problem in my Program. I cannot paste the whole program as it is huge so just pasting the lines i think are necessary. I am passing a integer array pointer to a...
12
by: Mike | last post by:
Consider the following code: """ struct person { char *name; int age; }; typedef struct person* StructType;
0
by: wellingj | last post by:
A little back ground on what I'm trying to do: I'm making a generic weighted graph class (vertexes and edges althought I don't call them that) to implement some pathfinding algorithms like A* and D*....
8
by: S. | last post by:
Hi all, Can someone please help me with this? I have the following struct: typedef struct { char *name; int age; } Student;
4
by: arnuld | last post by:
I am passing an array of struct to a function to print its value. First I am getting Segfaults and weired values. 2nd, is there any elegant way to do this ? /* Learning how to use an array...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
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...

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.