change USE of MFC
ocx ファイルがあり、それをwin32 アプリケーションで使用したいので、次のようにUSE MFC in a Static Library
進めます。
#import "C:\\Program Files\\GeoSDK\\LiveX_8300.ocx"
int CALLBACK WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// Register our Window class
WNDCLASS wndclass;
wndclass.style = CS_VREDRAW | CS_HREDRAW;
wndclass.lpfnWndProc = &WindowProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = NULL;
wndclass.hCursor = NULL;
wndclass.hbrBackground = reinterpret_cast <HBRUSH> (COLOR_BTNFACE + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName =windowClassName;
::RegisterClass(&wndclass);
// Create our main, raw win32 API window
// We create the window invisible (meaning that we do not provide WS_VISIBLE as the window style parameter), because making it visible and then
// adding a HwndSource will make it flicker.
HWND mainWindow = ::CreateWindow(
windowClassName,
windowTitle,
0,
CW_USEDEFAULT,
CW_USEDEFAULT,
windowWidth,
windowHeight,
NULL,
NULL,
hInstance,
0);
::ShowWindow (mainWindow, nCmdShow);
::UpdateWindow( mainWindow );
//ocx
//_DLiveX p;
typedef HRESULT (WINAPI *PFonc)(IUnknown*, HWND,IUnknown**);
HINSTANCE hDLL2 = ::LoadLibrary(TEXT("atl.dll"));
if (!hDLL2)
return 1;
PFonc AtlAxAttachControl = (PFonc) ::GetProcAddress(hDLL2,"AtlAxAttachControl");
CLSID clsid = GetClsid();
IID DIID__DLiveX = GetDIID__DLiveX();
RECT rect;
::GetClientRect(mainWindow,&rect);
container = ::CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT","",WS_CHILD | WS_VISIBLE,100,100,rect.right,rect.bottom,mainWindow,0,hInstance,0);
AtlAxWinInit();
HRESULT hr = ::CoInitialize(NULL);
LIVEXLib::_DLiveX *p;
hr = CoCreateInstance(clsid,
0,
CLSCTX_ALL,
DIID__DLiveX,
reinterpret_cast<void**>(&p)) ;
if(FAILED(AtlAxAttachControl((IUnknown*)p, container, 0))){
p->Release();
return -1;
MessageBox(HWND_DESKTOP, "FAILED(AtlAxAttachControl(pitd, container, NULL))", "Error", MB_ICONERROR | MB_OK);
}
while(hr == S_OK)
p->CreateX();
プログラムを実行すると、風にアクティブXが接続されましたが、メソッドを呼び出すと、このエラーが発生しました。SetPropertyUnhandled exception at 0x752a812f in test1.exe: Microsoft C++ exception: _com_error at memory location 0x0012fdbc..
メソッドまたはこのようなものを呼び出す必要があることはわかっていますが、方法がわかりません