C++ で記述され、DLL としてコンパイルされた関数があり、これを Delphi アプリケーションで使用したいと考えています。
スクレイパー.cpp:
SCRAPER_API bool ScraperGetWinList(SWin winList[100])
{
iCurrWin=0;
memset(winList,0,100 * sizeof(SWin));
return EnumWindows(EnumProcTopLevelWindowList, (LPARAM) winList);
}
Scraper.h:
#ifdef SCRAPER_EXPORTS
#define SCRAPER_API __declspec(dllexport)
#else
#define SCRAPER_API __declspec(dllimport)
#endif
struct SWin
{
char title[512];
HWND hwnd;
};
extern "C" {
SCRAPER_API bool ScraperGetWinList(SWin winList[100]);
}
これは、Delphi アプリケーションで関数を宣言する方法です。
type
tWin = record
Title: Array [0..511] of Char;
hWnd: HWND;
end;
tWinList = Array [0..99] of tWin;
function ScraperGetWinList(var WinList: tWinList): Boolean; stdcall; external 'Scraper.dll';
関数は機能しますが、終了すると、Debugger Fault Notification: Project ... faulted with message: ''access violation at 0x0012f773: write of address 0xffffffc0' を受け取ります。プロセスが停止しました。Step または Run を使用して続行します。
__stdcall
Scraper.cpp と Scraper.h に(の後に)を追加するSCRAPER_API bool
と、Delphi アプリケーションがまったく起動しません。プロシージャ エントリ ポイント ScraperGetWinList がダイナミック リンク ライブラリ Scraper.dll に見つかりませんでした。