Friday, January 23, 2009

Create a MFC support (CString) win32 dll using EVC++

Step 1: EVC++
New project->WinCE Dynamic-link library->Simple Window CE DLL ->


Step 2: Add header aaa.h file:

#ifdef TWOTECHBT_EXPORTS //cannot use numbers here like "2TBT_EXPORTS" will get fatal error C1016: #if[n]def expected an identifier"
#define TWOTECHBTLIB_API __declspec(dllexport)
#else
#define TWOTECHBTLIB_API __declspec(dllimport)
#endif
// Use "C" naming convention for methods.

#ifdef __cplusplus
extern "C" {
#endif


TWOTECHBTLIB_API BOOL WINAPI Initialize();
TWOTECHBTLIB_API BOOL WINAPI Deinitialize();
TWOTECHBTLIB_API BOOL WINAPI GetLocalBluetoothAddressName(
TCHAR *bsAddress, TCHAR *bsName);


#ifdef __cplusplus
}
#endif

Step 3: Settings->C/C++->Preprocessor->Add "TWOTECHBTLIB"

Step 4: aaa.cpp file: may need use following to replace default dllmain

BOOL APIENTRY Dllentry( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

Step 5: in order to use CString, add following to stdafx.h


#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers

#include // MFC core and standard components
#include // MFC extensions

#if defined(_WIN32_WCE) && (_WIN32_WCE >= 211) && (_AFXDLL)
#include // MFC support for Internet Explorer 4 Common Controls
#endif

#ifndef _AFX_NO_AFXCMN_SUPPORT
#include // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

No comments: