Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default CopyMemory - Array of UDTs referenced as a pointer to a string

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?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default CopyMemory - Array of UDTs referenced as a pointer to a string

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...

"Mark Stacey" wrote:

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?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default CopyMemory - Array of UDTs referenced as a pointer to a string

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.

"Mark Stacey" wrote:

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?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default CopyMemory - Array of UDTs referenced as a pointer to a string

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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default CopyMemory - Array of UDTs referenced as a pointer to a string

Can I just do this:

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

?



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
last number array from string Michael Excel Worksheet Functions 17 August 1st 05 07:30 PM
Passing a String in Array to Range as String [email protected] Excel Programming 2 September 1st 04 01:13 AM
Copy Array pointer rather than entire array R Avery Excel Programming 2 August 24th 04 08:28 PM
Vlookup, table array is referenced in another cell edsox5 Excel Programming 7 March 6th 04 12:03 AM
Convert a string to an array Dana DeLouis[_5_] Excel Programming 0 September 30th 03 04:02 AM


All times are GMT +1. The time now is 08:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"