Here is the code:
#define APP_NAME "COM Example (ch 5)"
#define WIDTH 100
#define HEIGHT 100
#include
#include
typedef IUnknown* (*CREATEFUNCPTR)() ;
IUknown* CallCreateInstance( HWND hWnd, char* name )
{
HINSTANCE hComponent = ::LoadLibrary( name );
if( hComponent == NULL )
{
MessageBox( hWnd, "INVALID FILE NAME", "ERROR", MB_OK );
return NULL;
}
CREATEFUNCPTR CreateInstance = (CREATEFUNCPTR)::GetProcAddress( hComponent, "CreateInstance" );
if( CreateInstance == NULL )
{
MessageBox( hWnd, "COULD NOT LOCATE CreateInstance", "ERROR", MB_OK );
return NULL;
}
return CreateInstance();
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
default:
return DefWindowProc( hWnd, msg, wParam, lParam );
}
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int )
{
HWND hWnd;
MSG msg;
WNDCLASS wc;
wc.cbClsExtra = NULL;
wc.cbWndExtra = NULL;
wc.hbrBackground = (HBRUSH)GetStockObject( GRAY_BRUSH );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = APP_NAME;
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW / CS_VREDRAW;
RegisterClass( &wc );
hWnd = CreateWindow( APP_NAME, APP_NAME, WS_OVERLAPPEDWINDOW, 0, 0, WIDTH, HEIGHT, NULL, NULL, hInstance, NULL );
ShowWindow( hWnd, SW_SHOW );
UpdateWindow( hWnd );
while( GetMessage( &msg, 0, 0, 0 ) == TRUE )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
}
Here is the problem:
Compiling...
win_main.cpp
C:\Programming\C++\COM_ch5\win_main.cpp(10) : error C2143: syntax error : missing '';'' before ''*''
C:\Programming\C++\COM_ch5\win_main.cpp(10) : error C2501: ''IUknown'' : missing storage-class or type specifiers
C:\Programming\C++\COM_ch5\win_main.cpp(11) : error C2501: ''CallCreateInstance'' : missing storage-class or type specifiers
C:\Programming\C++\COM_ch5\win_main.cpp(28) : error C2440: ''return'' : cannot convert from ''struct IUnknown *'' to ''int''
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
win_main.obj - 4 error(s), 0 warning(s)
I believe errors basically say that IUnKnown is undifined; why? Help.