GHCはCのコンパイルも出来ます。C言語でCOMクライアントを参考にして、SQL server, MS-Access にアクセスする ADODBConnection に接続してみました。
#include "stdio.h" #include "windows.h" #include "objbase.h" typedef struct tagMyVTable { /* VTableの定義 MyVTalbe */ void *p1; /* QueryInterface */ void *p2; /* AddRef */ ULONG (__stdcall *Release)(void* _this); /* 継承されているからいつもここ */ void *p3; /* GetTypeInfoCount */ void *p4; /* GetTypeInfo */ void *p5; /* GetIdsOfNames */ void *p6; /* Invoke */ } MyVTable; typedef struct tagIClass1 { MyVTable *lpVtbl; } _IClass1; const GUID CLSID_ADODBConnection28 = {0x00000514,0000,0x0010,{0x80,0x00,0x00,0xAA,0x00,0x6D,0x2E,0xA4}}; /* CLSID */ const GUID IID_IDispatch_unsafe = {0x00020400,0x0000,0x0000,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}}; /* IID */ int main(int argc, char* argv[]) { HRESULT hResult; _IClass1* pIClass1; CoInitialize(0); hResult = CoCreateInstance( &CLSID_ADODBConnection28, NULL, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, &IID_IDispatch_unsafe, (void**)&pIClass1); if( SUCCEEDED( hResult ) ) { printf("SUCCEEDED!\n"); }else{ printf("ERROR occured = %08x\n", hResult); return 0; } pIClass1->lpVtbl->Release( (void*)pIClass1 ); CoUninitialize(); return 0; }
PS D:\lang\COM> ghc comtest.c -lole32 -o comtest PS D:\lang\COM> ./comtest SUCCEEDED!