R
RYoung
Given this native struct:
typedef struct vendor
{
char name[20];
} VENDOR
I want to make managed equivalent, so I did this:
public value struct Vendor
{
public: String^ Name;
}
The managed Vendor type needs to be marshaled to void* so that an instance
of it can be passed to a native function (in the BerkeleyDB API):
Vendor^ vendor = gcnew Vendor();
vendor->Name = "Ron";
IntPtr vendorptr = Marshal::AllocHGlobal(Marshal::SizeOf(Vendor));
Marshall::StructureToPtr( vendor, vendorptr, false );
mydb.put( NULL, &key, &vendorptr, 0 );
Marshal::FreeHGlobal(vendorptr);
The "mydb.put()" method writes data to a file in a format used by
BerkeleyDB.
Note that an example application using the C-style structure above allows me
to write and read data to that file.
When I try using my managed structure, I can write but the read fails. This
leads me to believe that I need to define my structure differently (?)
Any comments on that question and the code is appreciated.
Ron
typedef struct vendor
{
char name[20];
} VENDOR
I want to make managed equivalent, so I did this:
public value struct Vendor
{
public: String^ Name;
}
The managed Vendor type needs to be marshaled to void* so that an instance
of it can be passed to a native function (in the BerkeleyDB API):
Vendor^ vendor = gcnew Vendor();
vendor->Name = "Ron";
IntPtr vendorptr = Marshal::AllocHGlobal(Marshal::SizeOf(Vendor));
Marshall::StructureToPtr( vendor, vendorptr, false );
mydb.put( NULL, &key, &vendorptr, 0 );
Marshal::FreeHGlobal(vendorptr);
The "mydb.put()" method writes data to a file in a format used by
BerkeleyDB.
Note that an example application using the C-style structure above allows me
to write and read data to that file.
When I try using my managed structure, I can write but the read fails. This
leads me to believe that I need to define my structure differently (?)
Any comments on that question and the code is appreciated.
Ron