Re: Array setup Question



Jake Thompson wrote:
Hello

I have the following defined structure

struct cm8linkstruc
{
char *type; /* type of item*/
char *desc; /* description of item */
char *item_increment; /* increment value for item in
folder */
char *itemid; /* id of returned item */
int count; /*total count of array */
};


In the function I have this

struct cm8linkstruc **cm8link;

If I want to allocate 50 occurrences of this array then if the
following correct? It appears to be correct at least at a compile level
because it compiles

/*Allocate the array for use over in the dll */
As soon as you say `dll', it's either irrelevant -- or off topic in this newsgroup.
cm8link = (struct cm8linkstruc **) malloc(50 * sizeof(struct
cm8linkstruc *));
Better:
cm8link = malloc(sizeof *cm8link * 50);

Since malloc() returns a pointer to void and such pointer is convertible to any pointer to object the cast is unnecessary -- and should be avoided (it can hide, for example, the failure to include <stdlib.h>.

Further, using the `sizeof object' form is often preferable to the `sizeof(type)' form; it the type happens to be changed, it makes for one less change that need be made...
and, of course, make sure the malloc() succeeded.
for(h = 0; h< 50 ; h++)
{
cm8link[h] = (struct cm8linkstruc *) malloc(sizeof(struct
cm8linkstruc));
Better:
cm8link[h] = malloc(sizeof **cm8link);
and, of course, make sure the malloc() succeeded
cm8link[h]->type = 0;
cm8link[h]->desc = 0;
cm8link[h]->item_increment = 0;
cm8link[h]->itemid = 0;
cm8link[h]->count = 0;
}

I have a function in a dll that will add values to the array and then
pass the populated array back to the calling exe

If I am on the right track then would I pass &cm8link to my function in
my dll in order to use it to populate it before I return from the

Again either this `dll' stuff is irrelevant or off topic.

called function?

HTH,
--ag
--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
"You can't KISS* unless you MISS**"
[*-Keep it simple, stupid. **-Make it simple, stupid.]
.



Relevant Pages

  • Re: C# - Problem to receive data from a C++ Dll
    ... I'm asking me something else also: the dll I'm using is a dll which was ... created by embedded Visual C++ 3.0 and I want to use it on a Pocket PC 2003 ... > array to a single char array? ... > (pointer to a pointer to a pointer to a character....) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Need a method to send byte arrays from Unmanaged C DLL to VB
    ... before calling the C routine. ... you can use a StringBuffer instead of a byte array. ... from a C DLL to VB? ... with ByRef Byteas a parameter, then treating it in C as a pointer to ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Array Pointers in C#, calling C++ DLL
    ... > array in my calling function after use. ... > But I can fix the deallocation problem in the dll. ... public static extern int dll_dbl_read( ... The dll function sets this null pointer into a valid pointer by allocating ...
    (microsoft.public.dotnet.languages.csharp)
  • Pointer to LabVIEW Array
    ... When I write a C .dll that takes a LabVIEW array, ... LabVIEW passes a pointer into LabVIEW's memory to the array to C.  ...
    (comp.lang.labview)
  • Cant pass simple array to a C++ DLL
    ... I am having some problems with passing an array to a C++ dll. ... get a pointer and store the first 3 int16's pointed to by the ... Here is my test code: ...
    (microsoft.public.dotnet.framework.interop)