Bonjour, j' essai de trouver un moyen de remplir des arrays/matrices C++ par des arrays/matrices de string/UDT/double VBA, dans le but de faire des operations dans ma DLL appelées par C++...
L'article
[ Lien ] de MS annonce qu'il n'est pas possible de remplir des SAFEARRAYS definis dans des DLL "classiques" et qu'il faut faire une DLL COM...
Cet article donne un exemple de construction d'une telle DLL mais si j'arrive à Builder le projet sous Visual Basic 6, je n'y arrive pas depuis Visual Studio .Net 2003
Voilà ce qu'ils font :
'---------------------------
Sample 2
This sample calculates the sum of long integers in a SAFEARRAY using a function in an ActiveX DLL created with the ActiveX Template Library (ATL) wizard.
1. In Visual C create an ATL DLL using the ATL COM AppWizard. Name it MyAtlDll.
2. From the Insert menu, select New ATL Object. Highlight Objects in the category list and select Simple Object in the Objects list. Click Next. Type in MyClass in the Short Name field, and then click the Attributes tab. Check the following options and then click OK:
Threading Model: Apartment
Interface: Dual
Aggregation: Yes
3. On the ClassView pane in the workspace, right-click IMyClass and select Add Method. Type AddLongs in the Method Name text box and type the following in the Parameters text box:[in,out] SAFEARRAY (long) *psaMyArray, [in,out] long *plSum
Note for Visual C version 6.0: If you are using Visual C version 6.0 you may receive the following error message:
Unable to create the function because the header or the implementation file could not be found.
This is a known issue in the wizard of Visual C version 6.0. You can by pass this error by manually changing the parameters for the AddLongs method in the header, source and .idl files as explained here:
In the Parameters list type in: [in,out] long *psaMyArray, [in,out] long *plSum
On the FileView tab in the workspace, expand MyAtlDll files. Under the header files double-click the MyClass.h header file. At the very end of this file you will find the declaration of your method: STDMETHOD(AddLongs)(/*[in,out]*/ long *psaMyArray, /*[in,out]*/ long *plSum);
Change it to the following: STDMETHOD(AddLongs)(/*[in,out]*/ SAFEARRAY **psaMyArray, /*[in,out]*/ long *plSum);
Under the Source Files list double-click MyClass.cpp. Here you will find the implementation of your method. Change the following line: STDMETHODIMP CMyClass::AddLongs(long *psaMyArray, long *plSum)
to: STDMETHODIMP CMyClass::AddLongs(SAFEARRAY **psaMyArray, long *plSum)
Also, under the Source Files list, double-click the .idl file (the only one with an .idl extension) and locate the following line: [id(1), helpstring("method AddLongs")] HRESULT AddLongs([in,out] long *psaMyArray, [in,out] long *plSum);
Change it to: [id(1), helpstring("method AddLongs")] HRESULT AddLongs([in,out] SAFEARRAY(long) *psaMyArray, [in,out] long *plSum);
1. Double-click the implementation file, MyClass.cpp, under the Source Files list. In the implementation file add the following code to your function: STDMETHODIMP CMyClass::AddLongs(SAFEARRAY * * psaArray, long * plSum)
{
// TODO: Add your implementation code here
long lElements; // number of elements in the array
long iCount;
HRESULT lResult; // return code for OLE functions
long *pArrayElements; // pointer to the elements of the array
// initializing the output
*plSum=0;
// checking if it is a one-dimensional array
if ( (*psaArray)->cDims != 1 ) return(E_FAIL);
// checking if it is an array of longs
if ( (*psaArray)->cbElements != 4 ) return(E_FAIL);
// how many elements are there in the array
lElements=(*psaArray)->rgsabound[0].cElements;
// locking the array before using its elements
lResult=SafeArrayLock(*psaArray);
if(lResult)return(lResult);
// using the array
pArrayElements=(long*) (*psaArray)->pvData;
for (iCount=0; iCount<lElements; iCount++)
*plSum = *plSum + pArrayElements[iCount];
// releasing the array
lResult=SafeArrayUnlock(*psaArray);
if (lResult) return(lResult);
return S_OK;
}
2. Build the DLL by pressing the F7 key.
3. In Visual Basic, create a new Standard EXE project. Form1 is created by default.
4. Place a command button named Command1 on Form1.
5. Select References from the Project menu and add a reference to the ActiveX DLL created previously (MyAtlDll).
6. Paste the following code into the Click event of Command1: Private Sub Command1_Click()
Dim MyObj As New MYATLDLLLib.MyClass
Dim ArrayOfLongs(3) As Long
Dim lSum As Long
ArrayOfLongs(0) = 1
ArrayOfLongs(1) = 2
ArrayOfLongs(2) = 3
MyObj.AddLongs ArrayOfLongs, lSum
MsgBox "Result from ATL dll = " & Str$(lSum)
End Sub
7. Press F5 to run your project.
8. Click Command1. You should see a message box that displays the value 6 returned from the AddLongs method.
'-------------------------
J'ai buildé sous Visual C++ 6 puisque je n'arrive pas à suivre leurs instruction de Visual C++ de VStudio .net 2003
ca marche ... mais...
Qd je rebuild ma dll (avec Visual C++ de VisualStudio.net 2003) je choppe comme erreur
MyAtlDll error PRJ0019: A tool returned an error code from "Performing registration"
MyAtlDll warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
MyAtlDll warning LNK4222: exported symbol 'DllCanUnloadNow' should not be assigned an ordinal
MyAtlDll warning LNK4222: exported symbol 'DllGetClassObject' should not be assigned an ordinal
MyAtlDll warning LNK4222: exported symbol 'DllRegisterServer' should not be assigned an ordinal
MyAtlDll warning LNK4222: exported symbol 'DllUnregisterServer' should not be assigned an ordinal
Voilà je ne sais plus quoi faire...
Qqn peut il m'aider à debuguer sous Visual C++ VS.NET03

wis : in tartiflette I trust (like the others)
