Hi,
Thank you very much for your kind help the other day.
Last time I got stuck in the method of outputting in the BSTR structure and passing it to VB, but this time I got stuck in the method of passing it from VB to VC++ as input.
I thought I should do the opposite of what I did last time, but maybe because I'm inexperienced, it didn't go so easily...So, if you don't mind, can I ask for your help?
<What I want to do>
I would like to know how to pass a structure marshaled in VB to VC++ as a BSTR structure.
VB(screen/FORM):Structure(MarshalAs(UnmanagedType.Bstr)
↓
VC++(DLL):typedef(BSTR)
<Development Environment>
Windows7(32bit)
VisualStudio2008(VB/VC++)
<Execution Environment>
Windows7(32bit)
Thank you.
What I have tried:
I tried the following source code with reference to the previous solution, but an error occurred when the Bstr structure was referenced on the VC++ side.
I want to call the function with the "tpNonPosDet2" structure on the VB side as an argument and receive the data as the "NPOS_DETAIL_UPD2" structure on the VC++ side.
【esql_com.h】
typedef struct {
char szFunctionFlag[2];
char szServiceNo[16];
char szPosNo[6];
char szSeqNo[6];
char szCreateDate[10];
char szCreateTime[6];
char szSalMoney[13];
char szRiyuCode[4];
char szServiceRank[4];
char szServiceRankAdd[4];
char szServiceTime[6];
char szChangeTime[6];
char szTantoCode[10];
char szCustKubn[4];
char szKozaNo[27];
char szKozaType[4];
} NPOS_DETAIL_UPD;
typedef struct {
BSTR szFunctionFlag;
BSTR szServiceNo;
BSTR szPosNo;
BSTR szSeqNo;
BSTR szCreateDate;
BSTR szCreateTime;
BSTR szSalMoney;
BSTR szRiyuCode;
BSTR szServiceRank;
BSTR szServiceRankAdd;
BSTR szServiceTime;
BSTR szChangeTime;
BSTR szTantoCode;
BSTR szCustKubn;
BSTR szKozaNo;
BSTR szKozaType;
} NPOS_DETAIL_UPD2;
__declspec(dllexport) int __stdcall Esql_UpNonPos(PS_HEADER_UPD *lpHeader, long *nIndexNum, NPOS_DETAIL_UPD2 *lpDetail);
【Esql_com.sc】
__declspec(dllexport) int __stdcall Esql_UpNonPos
(PS_HEADER_UPD *lpHeader, long *nIndexNum, NPOS_DETAIL_UPD2 *lpDetail)
{
long lCount=0;
int ii;
int nSqlstate; char *work; PS_HEADER_UPD wk_Header; NPOS_DETAIL_UPD wk_Detail; long iRet; NPOS_DETAIL_UPD2 npos; int idx[1], lb, ub; static char bufa[1024]; static wchar_t bufw[1024]; static size_t st; static char mbs[256];
EXEC SQL WHENEVER SQLERROR GOTO :SQL_ERROR;
EXEC SQL SET TRANSACTION READ WRITE;
MessageBox( NULL, TEXT("Esql_UpNonPos"), TEXT("Esql_com.sc"), MB_OK);
MessageBox( NULL, TEXT(lpHeader->szServiceNo), TEXT("Esql_com.sc"), MB_OK);
setlocale(LC_ALL,"Japanese");
idx[0] = 0;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
for(ii=0; ii<*nIndexNum; ii++) {
npos = lpDetail[idx[0]];
MessageBox( NULL, TEXT(" 0.1 START"), TEXT("Esql_UpNonPos"), MB_OK);
*bufa = 0x00;
wcsncpy_s(bufw, 1024, npos.szFunctionFlag, 2);
wcstombs_s(&st, NULL, 0, &bufw, 1024);
wcstombs_s(&st, &bufa[0], st, &bufw, 1024);
memset(wk_Detail.szFunctionFlag, '\0', sizeof(wk_Detail.szFunctionFlag));
strncpy_s(wk_Detail.szFunctionFlag, sizeof(wk_Detail.szFunctionFlag), bufa, 2-1);
MessageBox( NULL, TEXT(" 0.1 END"), TEXT("Esql_UpNonPos"), MB_OK);
MessageBox( NULL, TEXT(wk_Detail.szFunctionFlag), TEXT("Esql_UpNonPos Structure 1"), MB_OK);
・
・
・
【API_Refer.vb】
<DllImport("Esql_DLL.dll", CharSet:=CharSet.Ansi)> _
Public Function Esql_UpNonPos(<[In]()> ByVal Up_dtpPSHead As tpPS_Hed2, ByRef RecordCnt As Long, <[In]()> ByVal Up_dtpNonPosDet() As tpNonPosDet2) As Integer
End Function
【mdlPkSrv.vb】
<StructLayout(LayoutKind.Sequential)> _
Structure tpNonPosDet2
<MarshalAs(UnmanagedType.BStr)> Dim strShoriFlg As String
<MarshalAs(UnmanagedType.BStr)> Dim strSrvNo As String
<MarshalAs(UnmanagedType.BStr)> Dim strPosNo As String
<MarshalAs(UnmanagedType.BStr)> Dim strTuuban As String
<MarshalAs(UnmanagedType.BStr)> Dim strToriDate As String
<MarshalAs(UnmanagedType.BStr)> Dim strToriTime As String
<MarshalAs(UnmanagedType.BStr)> Dim strKingaku As String
<MarshalAs(UnmanagedType.BStr)> Dim strRiyuCd As String
<MarshalAs(UnmanagedType.BStr)> Dim strSrvRank As String
<MarshalAs(UnmanagedType.BStr)> Dim strAddSrvRank As String
<MarshalAs(UnmanagedType.BStr)> Dim strSrvTime As String
<MarshalAs(UnmanagedType.BStr)> Dim strChgTime As String
<MarshalAs(UnmanagedType.BStr)> Dim strHanbaiinCd As String
<MarshalAs(UnmanagedType.BStr)> Dim strCostomKbn As String
<MarshalAs(UnmanagedType.BStr)> Dim strKozaNo As String
<MarshalAs(UnmanagedType.BStr)> Dim strKozaSbh As String
End Structure
【frmPkSrv1.vb】
Ret = Esql_UpNonPos(dtp_GotHedData, RecordCnt, dtp_NonPosDet)