掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
C++Builderで作成したDLLからVBアプリのコールバック(引数に構造体の配列を含む)を呼ぶには (ID:125048)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
> 先にも書いたと思いますが、 > C側でVBが扱える構造体の配列をつくることが出来ないらしいので、 > > Sub Callback(ByRef b() As PPP) > というのはムリです。 前言撤回させてください。 調べ方が悪かったらしく、SafeArrayCreate関数ではなく、 SafeArrayAllocDescriptor,SafeArrayAllocDataを使えば設定できました。 以下サンプルソース /* C側ソース(VC6で作成) */ #include <windows.h> extern "C" { #endif typedef struct { long int kekka; long int waruatai; } TAMESI; __declspec( dllexport ) HRESULT WINAPI AttachEventProc( void ( CALLBACK *lpCallback )( LPSAFEARRAY* ) ) { TAMESI tElement; SAFEARRAY* psaRelation; long int index; static const int size = 5; if ( FAILED( SafeArrayAllocDescriptor( 1, &psaRelation ) ) ) { return E_UNEXPECTED; } /* 要素のサイズを設定 */ psaRelation->cbElements = sizeof( TAMESI ); psaRelation->fFeatures = FADF_STATIC; /* 配列のサイズを設定 */ psaRelation->rgsabound[ 0 ].cElements = size; psaRelation->rgsabound[ 0 ].lLbound = 0; if ( FAILED( SafeArrayAllocData( psaRelation ) ) ) { SafeArrayDestroyDescriptor( psaRelation ); return E_UNEXPECTED; } /* 配列に設定 */ SafeArrayLock( psaRelation ); for ( index = 0; index < size; ++index ) { tElement.waruatai = index + 1; tElement.kekka = 100 / ( index + 1 ); SafeArrayPutElement( psaRelation, &index, &tElement ); } SafeArrayUnlock( psaRelation ); /* コールバック関数の呼び出し */ ( *lpCallback )( &psaRelation ); /* 配列の削除 */ SafeArrayDestroyData( psaRelation ); SafeArrayDestroyDescriptor( psaRelation ); return S_OK; } #ifdef __cplusplus } #endif ' VB側Declare宣言文 Public Declare Function AttachEventProc Lib "test.dll" (ByVal func As Any) As Long
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.