begin process at 2012 05 29 03:14:08
  Trouver un code source :
 
dans
 
Accueil > Forum > 

C++ & C++ .NET

 > 

Divers

 > 

Général

 > 

DLL COM et SAFEARRAYS


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

DLL COM et SAFEARRAYS

lundi 19 juin 2006 à 18:51:16 | DLL COM et SAFEARRAYS

wismerhill__

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)
lundi 19 juin 2006 à 19:24:51 | Re : DLL COM et SAFEARRAYS

BruNews

Administrateur CodeS-SourceS
Exemple NON COM:

GENERATEUR DE TABLEAUX DE NOMBRES POUR VB/VBA
http://www.vbfrance.com/code.aspx?ID=33938

ciao...
BruNews, MVP VC++
lundi 19 juin 2006 à 20:09:58 | Re : DLL COM et SAFEARRAYS

wismerhill__

Merci BruNews mais il me faut comprendre ce bug de DLL COM.
Je dois arriver à exporter de vba à C++ des matrices de n'importe quel type et des UDT chose non possible (d'apres MS) avec des objets non COM via les SAFEARRAY.

Il me faut qqch de tres portable, je suis donc vraiment embeté je sais remplir des tableaux de long/double mais pas de string avec des SAFEARRAY

 

CCL : mon bug court toujours et est toujours inexpliqué


wis :
in tartiflette I trust (like the others)



Cette discussion est classée dans : long, dll, out, in, addlongs


Répondre à ce message

Sujets en rapport avec ce message

ODBC Connect dialog: lacks text if api called from dll [ par mfritschi ] hi,i am writing an abstract data access framework. it enables us amongother things to access databases without being interested in theactual underlyin Effet Fade In / Fade Out sous DirectDraw 7 [ par ProGamer ] J'ai besoin de faire cet effet sous DD7. J'ai vu une méthode qui utilise le Gamma Ramp, mais il se trouve que le Gamma Ramp dépend du matériel. y'a-t- probléme d'écriture fichier [ par phoenixadb ] phoenixadbJ'ai un problème sur une fonction que je n'arrive pas à résoudremon nom de fichier est test.txtet ma fonction:void ecriturefichier(char* nom Embarquer une dll dans un executable [ par MetalDwarf ] Voila je voudrais embarquer une dll dans un executable, c est a dire la mettre en data dans mon fichier source, et la reecrire sur le disque dur a l e installer in c/c++ [ par justgreat ] J'aimerai bien savoir si quelqu'un a une source code ou a deja travaille pour faire sur c++ ou c ,un "installer" tres simple et silencieux!qui a pour help pour IN OUT dans une fonction [ par youpiyoyo ] j'ai essayé différente maniere sans pouvoir y arriverexemple (source trouvé sur ce site pour recup le chemin a partir d'un fichier):int GetFileDir(IN Je dois halluciner [ par luhtor ] J'ai bricoler quelque programme pour écriture lecture de fichier binaire. Si quelqu'un peut m'expliquer ce qui se passe. Voila un programme tout simp Problème d'interfacage d'une DLL écrite en C++ avec vba [ par pierrinot ] Bonjour, Je dois créer une DLL utilisable par un programme VBA. Je tombe sur un problème d'entête de fonctions. La DLL est bien compilée, mais lorsq returnourner un entier long long [ par dlamalice ] Bonjour,j'ai codé une dll toute bete et j'aimerai que cette dernière me retour un long long (64bit) statique.Mais quand je compile la ligne return ne dll pour vb6 [ par draluorg ] Salut a tous,J'essai de faire une dll en C pour utiliser sous vb6, mais je recois toujours le message "Bad dll Calling Convention" depuis vb6 :(Voici


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,655 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales