Loading and using an unmanaged DLL
Hi all
Im trying to load a dll programmed in C, but I'm not sure exactly how to go about it. I read the following article:
http://msdn.microsoft.com/msdnmag/issues/02/08/CQA/
My problem is that Im not quite sure how to handle the return types. In the header file I several type definitions. Below you see some of the type definitions and two of the methods availeble in the DLL.
/********************** H FILE TOP *************************/
#if
defined (OMA_LIB_INTERNAL)# define OMA_DLLEXPORT DLLEXPORT
#else
# define
#endif
/****** Constants *******/
#define OmaC_Ov_Global_Object_Path""
#define OmaC_Ov_Unspec_Str"unspecified"
/****** Type Definitions *******/
typedefstruct OmaT_Ov_Reader OmaT_Ov_Reader;
typedefstruct OmaT_Ov_Vector OmaT_Ov_Vector;
typedefstruct OmaT_Ov_Reader_Iterator OmaT_Ov_Reader_Iterator;
......
/******************** FUNCTIONS *************************/
OMA_DLLEXPORT OmaT_Ov_Reader *
Oma_Ov_Reader_Open (
OMA_DLLEXPORT OmaT_Ov_Vector *
Oma_Ov_Reader_Vector_Get (OmaT_Ov_Reader *ov_reader_ptr,
constchar *group_and_stat_name);
......
My question is: How I use import this DLL?
At the moment I have an idea that it should be something like the following, but I have no clue how to define the structs which Im using and which gets returned. See below:
publicclassOMAInterface
{
// I guess I have to make a C# struct to get the OmaT_Ov_Vector
[StructLayout(LayoutKind.Sequential)]
publicstructOmaT_Ov_Vector
{
// ? how would I go about creating a struct for this type?
}
// The same accounts for the OmaT_Ov_Reader which is used every time the ov file is read
[StructLayout(LayoutKind.Sequential)]
publicstructOmaT_Ov_Reader
{
// again I dont know how to construct this
}
// Conversion of types is not considered yet
[DllImport("opoma_opt.dll")]
publicstaticexternOmaT_Ov_Reader* Oma_Ov_Reader_Open (constchar *ov_file_name);
{}
// Conversion of types is not considered yet
[DllImport("opoma_opt.dll")]
publicstaticexternOmaT_Ov_Vector* Oma_Ov_Reader_Vector_Get (OmaT_Ov_Reader *ov_reader_ptr,constchar *report_name,constchar *obj_path,constchar *group_and_stat_name);
{}
}
Any help is much appreciated
Christian

