Re: passing struct from vb to c dll




<abhi.10dulkar@xxxxxxxxx> skrev i meddelandet
news:1152610732.377015.78160@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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

MBRINFO.szMember is a fixed length string 80 characters. It will be what you
say, 'Something' + 70 spaces. To get what you really want, you have to add a
f.ex. 'null' delimiter after 'Something' in the dll. Then you can extract
'Something' by:


Dim strMember As String

With pInfo
strMember = Left$(.szMember, Instr(.szMember, chr$(0)) -1)
End With

/Henning


.



Relevant Pages

  • Re: Marshaling char *... HELP, PLEASE!
    ... As soon as you need the C DLL to modify the string passed, you cannot use default string marshaling - StringBuilders are not supported in structs. ... code to only one struct with one char *, but when i try to call the ... "Cannot marshal field 'str' of type 'memmap': ...
    (microsoft.public.dotnet.framework.interop)
  • Re: passing struct from vb to c dll
    ... I am having some problem for getting values in struct from the c dll. ... Declare Function GetMemberInfo Lib "xyz" (pInfo As MBRINFO) As Long ... szMember is filled with assigned value which is "Something" folloed ...
    (comp.lang.basic.visual.misc)
  • passing structure to c dll from vb
    ... I am having some problem for getting values in struct from the c dll. ... Declare Function GetMemberInfo Lib "xyz" (pInfo As MBRINFO) As Long ... But, when I get value back on vb side, I noticed the value for szMember ...
    (microsoft.public.vb.winapi)
  • Passing a struct to c dll from vb
    ... I am having some problem for getting values in struct from the c dll. ... Declare Function GetMemberInfo Lib "xyz" (pInfo As MBRINFO) As Long ... But, when I get value back on vb side, I noticed the value for szMember ...
    (microsoft.public.vb.syntax)
  • Passing a struct to c dll from vb
    ... I am having some problem for getting values in struct from the c dll. ... Declare Function GetMemberInfo Lib "xyz" (pInfo As MBRINFO) As Long ... But, when I get value back on vb side, I noticed the value for szMember ...
    (microsoft.public.vb.syntax)