CopyMemory - Array of UDTs referenced as a pointer to a string

M

Mark Stacey

Data is sent to me by an API which returns a pointer to a "string" which
is actually a data structure. I use CopyMemory(Alias RtlMoveMemory) to
get access to this data in my own UDT's.
My problem arises in that sometimes the data will be returned as an
array of structs. The API doesn't provide for letting me know the size
of the array, and getting the length of the string just gives me the
length of one element.
The API is not written in VB, so I think that means it's a
null-terminated array, if so how do I copy each of the elements in my
own array of equivalent structure?
 
G

Guest

Strings are null terminated not arrays. Also known as ASCII Z. The API is
quite probably done in C. C doesn't tell you anything about the pointerjust
that something you are looking for starts at this point in memory. It is up
to the C Programmer to figure out how much memory you want to read. From a
Visual Basic stand point you are kind of lost. Unless you can find out how
many elements are in the array you will not be able to retrieve the values of
the array. Best of luck to you...
 
G

Guest

Sorry I just re-read your question. In C there is no such thing as a string.
There is only a null terminated array of characters. When you de-reference
the pointer to the arry you get the string. In C the de-reference retrieves
all characters up until Null or ASCII Z is returned.
 
M

Mark Stacey

So what if I passed the string (by reference) to a C dll, (not as
arbitrary as it sounds, I already use a C dll [well, C++, it's compiled
in MSVC, it's all ANSI-C tho] called from the VB app for some
calculations), which can then determine the length of the data, return
that value to VB, which then calculates the number of array elements,
and copies out each element into the UDT.

CopyMem into a string, then use MidB (MidB not Mid because this is not
all character data) to move into a temp string, and CopyMem that string
into the UDT, for each element.

That assumes that the array is stored contiguously, which as I
understand it is correct.

How do I determine the length of an array in C? I can't use any C++
code, all my C-code has to be able to be recompiled in other compilers.
 
M

Mark Stacey

Can I just do this:

double __stdcall lenArr( const char* strArr ) {
return (int)strlen( strArr );
}

?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top