I will be writing several .dll's to act as loadable Parser's for user settable hardware devices (somewhat similar to plugins). The .DLL's will be selected and loaded at run time by the user.
Several of the functions within the .DLL will be required to return a series of strings such as a list of supported features... or group of accessible locations... etc...
The returned strings will be displayed in a ListBox or Combobox within a vb.net application (which i will also be writing)...
I have spent a considerable length of time searching online (google, forums etc) and although I am new to VB.net, I do have some experience with Pascal, Delphi, C, C++ and VB and I understand the mechanics of dynamically loading using the LoadLibrary, FreeLibrary, GetProcAddress, etc... But I am now getting totally confused and frustrated by the Marshalling, importing, exporting, SafeArray, COleSafeArray, etc
Am i going about this the right way, or is there a better way of doing what i am trying to achieve.
What I have tried:
__declspec(dllexport) SAFEARRAY* _stdcall DriverGetLOT();
void FillSafeArray(OLECHAR FAR *sz, int iRow, COleSafeArray *sa)
{
VARIANT v;
long index[1];
index[0] = iRow;
VariantInit(&v);
v.vt = VT_BSTR;
v.bstrVal = SysAllocString(sz);
sa->PutElement(index, v.bstrVal);
SysFreeString(v.bstrVal);
VariantClear(&v);
}
SAFEARRAY* _stdcall DriverGetLOT()
{
DWORD saBounds[] = {4};
COleSafeArray saRet;
saRet.Create(VT_BSTR, 1, saBounds);
FillSafeArray(strBatchName.AllocSysString(),0,&saRet);
FillSafeArray(strWaferName.AllocSysString(),1,&saRet);
FillSafeArray(strExpectedYield.AllocSysString(),2,&saRet);
FillSafeArray(strOperatorName.AllocSysString(),3,&saRet);
return saRet.Detach(); }
// in Vb.NET
Public Class myClass
Private Declare Function DriverGetLOT Lib "Driver.dll"() As string()
Sub DoStuff()
Me.lbLOTinfo.Items.AddRange(DriverGetLOT())
end sub
end class