Hi!
I am stuck with this problem since a long time. I am
trying to return a list of strings from a DLL function
to the calling application like VB. For example, the
days of the week. But in the VB application I am getting
a type mismatch error.
I want to know if I am doing the right thing or not, can
somebody help, I'll be really grateful.
The VC++ function is :
STDMETHODIMP Cstring::listdays(VARIANT *days)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// TODO: Add your implementation code here
VARIANT vaResult[7];
for (int i=0; i<7;i++)
VariantInit(&vaResult);
char *day[10]
={"Monday","Tuesday","Wednesday","Thursday","Friday","Sa
turday","Sunday"};
CString s;
for(i=0; i<7;i++)
{
AfxMessageBox("entered for loop",MB_OK);
s.Format("%s",day);
AfxMessageBox(s,MB_OK);
vaResult.vt=VT_BSTR;
vaResult.bstrVal =
s.AllocSysString();
AfxMessageBox("allocated string",MB_OK);
}
days = &vaResult[0];
/*********/
return S_OK;
}
The VB code is :
Dim d As DBDLLLib.String
Private Sub Command1_Click()
Dim list() As Variant
list() = d.listdays()
For i = 1 To UBound(list)
List1.AddItem (list(i))
Next
End Sub
Private Sub Form_Load()
Set d = New DBDLLLib.String
End Sub
Thanks for reading!
bye!
[sig][/sig]
I am stuck with this problem since a long time. I am
trying to return a list of strings from a DLL function
to the calling application like VB. For example, the
days of the week. But in the VB application I am getting
a type mismatch error.
I want to know if I am doing the right thing or not, can
somebody help, I'll be really grateful.
The VC++ function is :
STDMETHODIMP Cstring::listdays(VARIANT *days)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// TODO: Add your implementation code here
VARIANT vaResult[7];
for (int i=0; i<7;i++)
VariantInit(&vaResult);
char *day[10]
={"Monday","Tuesday","Wednesday","Thursday","Friday","Sa
turday","Sunday"};
CString s;
for(i=0; i<7;i++)
{
AfxMessageBox("entered for loop",MB_OK);
s.Format("%s",day);
AfxMessageBox(s,MB_OK);
vaResult.vt=VT_BSTR;
vaResult.bstrVal =
s.AllocSysString();
AfxMessageBox("allocated string",MB_OK);
}
days = &vaResult[0];
/*********/
return S_OK;
}
The VB code is :
Dim d As DBDLLLib.String
Private Sub Command1_Click()
Dim list() As Variant
list() = d.listdays()
For i = 1 To UBound(list)
List1.AddItem (list(i))
Next
End Sub
Private Sub Form_Load()
Set d = New DBDLLLib.String
End Sub
Thanks for reading!
bye!
[sig][/sig]