Chapter 2
Developing Your Application
©
National Instruments Corporation
2-3
return FALSE;
}
Next, your application must use the Win32
GetProcAddress
function to
get the addresses of the NI-CAN functions your application needs to use.
For each NI-CAN function used by your application, you must define a
direct entry prototype. For the prototypes for each function exported by
nican.dll
, refer to the
NI-CAN Programmer Reference Manual
. The
following code fragment illustrates how to get the addresses of the
ncOpenObject
,
ncCloseObject
, and
ncRead
functions:
static NCTYPE_STATUS (_NCFUNC_ *PncOpenObject)
(NCTYPE_STRING ObjName,
NCTYPE_OBJH_P ObjHandlePtr);
static NCTYPE_STATUS (_NCFUNC_ *PncCloseObject)
(NCTYPE_OBJH ObjHandle);
static NCTYPE_STATUS (_NCFUNC_ *PncRead)
(NCTYPE_OBJH ObjHandle, NCTYPE_UINT32 DataSize,
NCTYPE_ANY_P DataPtr);
PncOpenObject = (NCTYPE_STATUS (_NCFUNC_ *)
(NCTYPE_STRING, NCTYPE_OBJH_P))
GetProcAddress(NicanLib, (LPCSTR)"ncOpenObject");
PncCloseObject = (NCTYPE_STATUS (_NCFUNC_ *)
(NCTYPE_OBJH))
GetProcAddress(NicanLib, (LPCSTR)"ncCloseObject");
PncRead = (NCTYPE_STATUS (_NCFUNC_ *)
(NCTYPE_OBJH, NCTYPE_UINT32, NCTYPE_ANY_P))
GetProcAddress(NicanLib, (LPCSTR)"ncRead");
If
GetProcAddress
fails, it returns a NULL pointer. The following code
fragment illustrates how to verify that none of the calls to
GetProcAddress
failed:
if ((PncOpenObject == NULL) ||
(PncCloseObject == NULL) ||
(PncRead == NULL)) {
FreeLibrary(NicanLib);
printf("GetProcAddress failed");
}
Your application needs to de-reference the pointer to access an NI-CAN
function, as illustrated by the following code:
NCTYPE_STATUS status;
NCTYPE_OBJH MyObjh;