VBA側宣言のByVal x As Stringと VBA側でStringの領域を確保しておくのがミソ
VC++側
extern "C" __declspec (dllexport) int __stdcall Test2(char *X, char *Y);
extern "C" __declspec (dllexport) int __stdcall Test2(char *X, char *Y)
{
Y[0] = 'A';
Y[1] = 'Z';
Y[2] = '@';
return 0;
}VB側
Private Declare Function Test2 Lib "testdll.dll" (ByVal x As String, _
ByVal y As String) As Long
Private Sub Command1_Click()
Dim ret As Long
Dim strKekka As String * 3
ret = Test2("123", strKekka)
MsgBox strKekka
End Sub
ネタ元