Hi everybody,

I'm used to C++ OOP principles but I've never really understood dll's very well. I'm working on a code segment as shown below. It's a dll function. What I need to know is can I compile it directly or do I need to do something special?

I'm using bloodshed and it doesn't compile with this. Do I need

#define API_DLLEXPORT extern "C" __declspec(dllexport)
HINSTANCE hIQ_Measure; // handle for IQ_Measure DLL
hIQ_Measure = LoadLibrary("IQ_Fact.dll"); // you only need to do this once
typedef IQ_RESULT_TYPE *(*DLL_PROC)( LPTSTR);
typedef IQ_RESULT_SWEEP_TYPE *(*DLL_SWEEP_PROC)(LPTSTR);
typedef LOG_RESULT_TYPE *(*DLL_LOG_PROC)(char *);
API_DLLEXPORT bool LabV_IQ_verify_TX_EVM ( char *sPara, int *pass,
int *num_results, char *description, char *test_name, char *result_text,
int test_result_pass[], double test_limit_upper[], double test_limit_lower[], double test_measure[] )
{
bool error=false;
IQ_RESULT_TYPE *ret;
DLL_PROC call;
int TestItem;
// obtain_control Dll Fuction
call = (DLL_PROC) GetProcAddress ( hIQ_Measure, "IQ_verify_TX_EVM" );
ret = call ( sPara );
// Move the structed data to return native data types.
if (ret->error_occur_flag)
error=true;
Transfer_struct_to_native_datatypes ( ret,
pass, num_results, description, test_name, result_text,
test_result_pass, test_limit_upper, test_limit_lower, test_measure );
return (error);
}

Please use the CODE tags around anything that is a block of code, it makes it easier to read.

#define API_DLLEXPORT extern "C" __declspec(dllexport)
HINSTANCE hIQ_Measure; // handle for IQ_Measure DLL
hIQ_Measure = LoadLibrary("IQ_Fact.dll"); // you only need to do this once
typedef IQ_RESULT_TYPE *(*DLL_PROC)( LPTSTR);
typedef IQ_RESULT_SWEEP_TYPE *(*DLL_SWEEP_PROC)(LPTSTR);
typedef LOG_RESULT_TYPE *(*DLL_LOG_PROC)(char *);
API_DLLEXPORT bool LabV_IQ_verify_TX_EVM ( char *sPara, int *pass,
int *num_results, char *description, char *test_name, char *result_text,
int test_result_pass[], double test_limit_upper[], double test_limit_lower[], double test_measure[] )
{
bool error=false;
IQ_RESULT_TYPE *ret;
DLL_PROC call;
int TestItem;
// obtain_control Dll Fuction
call = (DLL_PROC) GetProcAddress ( hIQ_Measure, "IQ_verify_TX_EVM" );
ret = call ( sPara );
// Move the structed data to return native data types.
if (ret->error_occur_flag)
error=true;
Transfer_struct_to_native_datatypes ( ret,
pass, num_results, description, test_name, result_text,
test_result_pass, test_limit_upper, test_limit_lower, test_measure );
return (error);
}

If you're getting any error message (compile or runtime), the actual error text would be useful.

The 'LoadLibrary' call is usually made from within a code block and not as part of global initialization. It would allow you to test for success or failure of the call.

(I'm pretty sure that calling LoadLibray to initialize a global variable is also bad form, but I'm willing to be corrected.)

If you have an error, do you still want to call Transfer_struct_to_native_datatypes ?

The code 'as written' appears to be intended as a DLL to be loaded by another application. (LabView maybe?) You will need to make sure your development environment is setup to build this as DLL as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.