Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I return a list of strings from a DLL function

Status
Not open for further replies.

himu

Programmer
Sep 25, 2000
2
US
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]

={&quot;Monday&quot;,&quot;Tuesday&quot;,&quot;Wednesday&quot;,&quot;Thursday&quot;,&quot;Friday&quot;,&quot;Sa

turday&quot;,&quot;Sunday&quot;};

CString s;
for(i=0; i<7;i++)
{
AfxMessageBox(&quot;entered for loop&quot;,MB_OK);
s.Format(&quot;%s&quot;,day);
AfxMessageBox(s,MB_OK);
vaResult.vt=VT_BSTR;
vaResult.bstrVal =

s.AllocSysString();
AfxMessageBox(&quot;allocated string&quot;,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]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top