I have been given a DLL ("InfoLookup.dll") that internally allocates structures and returns pointers to them from a lookup function. The structures contain string pointers:
extern "C"
{
struct Info
{
int id;
char* szName;
};
Info* LookupInfo( int id );
}
In C#, how can I declare the structure layout, declare the Interop call, and (assuming a non-null value is returned) utilize the string value? In other words, how do I translate the following into C#?
#include "InfoLookup.h"
void foo()
{
Info* info = LookupInfo( 0 );
if( info != 0 && info->szName != 0 )
DoSomethingWith( info->szName );
// NOTE: no cleanup here, the DLL is caching the lookup table internally
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…