Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. a simply question about dlls

a simply question about dlls

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
35 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Gerald Mercet

    you were right for the typo, i change it and it brought nothing into the way of no working of my application... have you any other idea because i don't succeed in solving my pb?:confused:

    J Offline
    J Offline
    Joaquin M Lopez Munoz
    wrote on last edited by
    #14

    How are you calling Maximum from VBA? From your fist post, seems like you're providing no arguments. This has underwent so many changes that maybe it'd be a good idea to post again the (relevant) code in its current form. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

    G 1 Reply Last reply
    0
    • J Joaquin M Lopez Munoz

      How are you calling Maximum from VBA? From your fist post, seems like you're providing no arguments. This has underwent so many changes that maybe it'd be a good idea to post again the (relevant) code in its current form. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      G Offline
      G Offline
      Gerald Mercet
      wrote on last edited by
      #15

      In my first post you could see thge following code : Public Declare Function Maximun Lib "D:\essai2\Debug\essai2.dll"(byval a as integer,byval b as integer) as integer In fact, in a vba project linked to an excel workbook, i put this code into a module window. And that's all i do. So, i don't know if answer properly to your question!?! regards

      J 1 Reply Last reply
      0
      • G Gerald Mercet

        In my first post you could see thge following code : Public Declare Function Maximun Lib "D:\essai2\Debug\essai2.dll"(byval a as integer,byval b as integer) as integer In fact, in a vba project linked to an excel workbook, i put this code into a module window. And that's all i do. So, i don't know if answer properly to your question!?! regards

        J Offline
        J Offline
        Joaquin M Lopez Munoz
        wrote on last edited by
        #16

        I mean, when you actually invoke the function Maximum, how do you do it? Do you actually pass two numbers? Also, your firs posts are probably obsolete by know (for instance, I guess you already corrected the Maximun/Maximum typo), so it'd be great if you repost the code in its actual form. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        G 1 Reply Last reply
        0
        • J Joaquin M Lopez Munoz

          I mean, when you actually invoke the function Maximum, how do you do it? Do you actually pass two numbers? Also, your firs posts are probably obsolete by know (for instance, I guess you already corrected the Maximun/Maximum typo), so it'd be great if you repost the code in its actual form. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

          G Offline
          G Offline
          Gerald Mercet
          wrote on last edited by
          #17

          Ok, i think that when you speak about invoking the function Maximum in VBA, it's to ask me how i use this function into another "sub or function", or how i do the declaration into vba? Because as i said below, i have only written into the module window the code the code you have read ("Public declare...") I didn't use any other function which call this routine, i call it directly from excel. Perhaps it's a mistake? And in excel, i put 2 values into 2 cells, for example, into A1 i put "2", and in A2, "5", so in another cell, i call the function Maximum thanks to the button "fx" in the toolbar. So, do i an error by proceeding like that? thanks for your patience. gerald

          J 1 Reply Last reply
          0
          • G Gerald Mercet

            Ok, i think that when you speak about invoking the function Maximum in VBA, it's to ask me how i use this function into another "sub or function", or how i do the declaration into vba? Because as i said below, i have only written into the module window the code the code you have read ("Public declare...") I didn't use any other function which call this routine, i call it directly from excel. Perhaps it's a mistake? And in excel, i put 2 values into 2 cells, for example, into A1 i put "2", and in A2, "5", so in another cell, i call the function Maximum thanks to the button "fx" in the toolbar. So, do i an error by proceeding like that? thanks for your patience. gerald

            J Offline
            J Offline
            Joaquin M Lopez Munoz
            wrote on last edited by
            #18

            thanks for your patience. No problem, we're building one of the most beatiful waterfall-like threads so far here in CP. Well, please post your code (that is, the VBA import code and the C++ part) to see how it looks like now. Little help can be provided without that. As for the means of invokation, in your particular scenario please locate the cursor on the cell where Maximum is invoked. At the upper area of Excel, just below the toolbars, you will have to see something like

            =Maximum(A1;A2)

            Otherwise, you're probably calling your function the wrong way. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

            G 1 Reply Last reply
            0
            • J Joaquin M Lopez Munoz

              thanks for your patience. No problem, we're building one of the most beatiful waterfall-like threads so far here in CP. Well, please post your code (that is, the VBA import code and the C++ part) to see how it looks like now. Little help can be provided without that. As for the means of invokation, in your particular scenario please locate the cursor on the cell where Maximum is invoked. At the upper area of Excel, just below the toolbars, you will have to see something like

              =Maximum(A1;A2)

              Otherwise, you're probably calling your function the wrong way. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

              G Offline
              G Offline
              Gerald Mercet
              wrote on last edited by
              #19

              Ok, as the app i test is for the moment just a test, the following code, called essai2.cpp, have only one function, "Maximum". (I have made sthg simple to learn first the syntax before doing sthg more complex) So: // essai2.cpp : Defines the initialization routines for the DLL. // #include "stdafx.h" #include "essai2.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // // Note! // // If this DLL is dynamically linked against the MFC // DLLs, any functions exported from this DLL which // call into MFC must have the AFX_MANAGE_STATE macro // added at the very beginning of the function. // // For example: // // extern "C" BOOL PASCAL EXPORT ExportedFunction() // { // AFX_MANAGE_STATE(AfxGetStaticModuleState()); // // normal function body here // } // // It is very important that this macro appear in each // function, prior to any calls into MFC. This means that // it must appear as the first statement within the // function, even before any object variable declarations // as their constructors may generate calls into the MFC // DLL. // // Please see MFC Technical Notes 33 and 58 for additional // details. // ///////////////////////////////////////////////////////////////////////////// // CEssai2App BEGIN_MESSAGE_MAP(CEssai2App, CWinApp) //{{AFX_MSG_MAP(CEssai2App) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CEssai2App construction CEssai2App::CEssai2App() { // TODO: add construction code here, // Place all significant initialization in InitInstance } ///////////////////////////////////////////////////////////////////////////// // The one and only CEssai2App object CEssai2App theApp; extern "C" __declspec(dllexport) int Maximum(int a,int b) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); int max; if(a

              J 1 Reply Last reply
              0
              • G Gerald Mercet

                Ok, as the app i test is for the moment just a test, the following code, called essai2.cpp, have only one function, "Maximum". (I have made sthg simple to learn first the syntax before doing sthg more complex) So: // essai2.cpp : Defines the initialization routines for the DLL. // #include "stdafx.h" #include "essai2.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // // Note! // // If this DLL is dynamically linked against the MFC // DLLs, any functions exported from this DLL which // call into MFC must have the AFX_MANAGE_STATE macro // added at the very beginning of the function. // // For example: // // extern "C" BOOL PASCAL EXPORT ExportedFunction() // { // AFX_MANAGE_STATE(AfxGetStaticModuleState()); // // normal function body here // } // // It is very important that this macro appear in each // function, prior to any calls into MFC. This means that // it must appear as the first statement within the // function, even before any object variable declarations // as their constructors may generate calls into the MFC // DLL. // // Please see MFC Technical Notes 33 and 58 for additional // details. // ///////////////////////////////////////////////////////////////////////////// // CEssai2App BEGIN_MESSAGE_MAP(CEssai2App, CWinApp) //{{AFX_MSG_MAP(CEssai2App) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CEssai2App construction CEssai2App::CEssai2App() { // TODO: add construction code here, // Place all significant initialization in InitInstance } ///////////////////////////////////////////////////////////////////////////// // The one and only CEssai2App object CEssai2App theApp; extern "C" __declspec(dllexport) int Maximum(int a,int b) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); int max; if(a

                J Offline
                J Offline
                Joaquin M Lopez Munoz
                wrote on last edited by
                #20

                Replace

                extern "C" __declspec(dllexport) int Maximum(int a,int b)

                with

                extern "C" __declspec(dllexport) int WINAPI Maximum(int a,int b)

                Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                G 1 Reply Last reply
                0
                • J Joaquin M Lopez Munoz

                  Replace

                  extern "C" __declspec(dllexport) int Maximum(int a,int b)

                  with

                  extern "C" __declspec(dllexport) int WINAPI Maximum(int a,int b)

                  Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                  G Offline
                  G Offline
                  Gerald Mercet
                  wrote on last edited by
                  #21

                  I have tried your suggestion without any success. so in the vba code i've done a simple Sub, which only call the function Maximum and put the result into a excel's cell, as following: /////////////////////////////////////////////////////////// Sub test22() Cells(5, 5) = Maximum(2, 6) End Sub ////////////////////////////////////////////////////////// when i play it, i have the following error message: (sorry but as my excel version is french, the error message is in english) so: "Entry point" Maximum of a dll which cannot be found in D:\essai2\Debug\essai2.dll. Of course after this message, i have checked if the path was correct, and it was!!! so, do you think that i'm unlucky X| X| X|

                  J C 3 Replies Last reply
                  0
                  • G Gerald Mercet

                    I have tried your suggestion without any success. so in the vba code i've done a simple Sub, which only call the function Maximum and put the result into a excel's cell, as following: /////////////////////////////////////////////////////////// Sub test22() Cells(5, 5) = Maximum(2, 6) End Sub ////////////////////////////////////////////////////////// when i play it, i have the following error message: (sorry but as my excel version is french, the error message is in english) so: "Entry point" Maximum of a dll which cannot be found in D:\essai2\Debug\essai2.dll. Of course after this message, i have checked if the path was correct, and it was!!! so, do you think that i'm unlucky X| X| X|

                    J Offline
                    J Offline
                    Joaquin M Lopez Munoz
                    wrote on last edited by
                    #22

                    Ok, now I think we got it. On the C++ part, leave it all as it is now (i.e., maintain the WINAPI thing, please). On the VBA part, replace your declaration with the following:

                    Public Declare Function Maximum Lib "D:\essai2\Debug\essai2.dll" Alias "_Maximum@8" (Byval m1 as long,Byval m2 as long) as long

                    I've tried it myself and it works, please tell me back if it did for you. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                    1 Reply Last reply
                    0
                    • G Gerald Mercet

                      I have tried your suggestion without any success. so in the vba code i've done a simple Sub, which only call the function Maximum and put the result into a excel's cell, as following: /////////////////////////////////////////////////////////// Sub test22() Cells(5, 5) = Maximum(2, 6) End Sub ////////////////////////////////////////////////////////// when i play it, i have the following error message: (sorry but as my excel version is french, the error message is in english) so: "Entry point" Maximum of a dll which cannot be found in D:\essai2\Debug\essai2.dll. Of course after this message, i have checked if the path was correct, and it was!!! so, do you think that i'm unlucky X| X| X|

                      J Offline
                      J Offline
                      Joaquin M Lopez Munoz
                      wrote on last edited by
                      #23

                      Et bien? (avec un air d'expectation) Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                      G 3 Replies Last reply
                      0
                      • J Joaquin M Lopez Munoz

                        Et bien? (avec un air d'expectation) Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                        G Offline
                        G Offline
                        Gerald Mercet
                        wrote on last edited by
                        #24

                        Sorry for this later answer, but in my job i'm not a full-time programmer, so i have others things to do(conference...) So, i tried your solution, and it didn't work at all, so i don't know what is wrong in my code or in sthg extern of the 2 environments. But, for the moment, i will try again checking if i haven't forgotten anything. So, before i will come back just a question, how do you find this solution, and what is this alias? thanks a lot

                        1 Reply Last reply
                        0
                        • J Joaquin M Lopez Munoz

                          Et bien? (avec un air d'expectation) Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                          G Offline
                          G Offline
                          Gerald Mercet
                          wrote on last edited by
                          #25

                          just for information the C++ code and vba code: //////VBA////////////////////////////////////////////////// Public Declare Function Maximum Lib "D:\essai2\Release\essai2.dll" Alias "_Maximum@8" (ByVal m1 As Long, ByVal m2 As Long) As Long Function test2(m As Long, n As Long) test2 = Maximum(m, n) If test2 = "" Then test2 = 0 Else test2 = test2 End If End Function Sub test22() Cells(5, 5) = Maximum(2, 6) //////C++///////////////////////////////////////////////// / essai2.cpp : Defines the initialization routines for the DLL. // #include "stdafx.h" #include "essai2.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // // Note! // // If this DLL is dynamically linked against the MFC // DLLs, any functions exported from this DLL which // call into MFC must have the AFX_MANAGE_STATE macro // added at the very beginning of the function. // // For example: // // extern "C" BOOL PASCAL EXPORT ExportedFunction() // { // AFX_MANAGE_STATE(AfxGetStaticModuleState()); // // normal function body here // } // // It is very important that this macro appear in each // function, prior to any calls into MFC. This means that // it must appear as the first statement within the // function, even before any object variable declarations // as their constructors may generate calls into the MFC // DLL. // // Please see MFC Technical Notes 33 and 58 for additional // details. // ///////////////////////////////////////////////////////////////////////////// // CEssai2App BEGIN_MESSAGE_MAP(CEssai2App, CWinApp) //{{AFX_MSG_MAP(CEssai2App) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CEssai2App construction CEssai2App::CEssai2App() { // TODO: add construction code here, // Place all significant initialization in InitInstance } ///////////////////////////////////////////////////////////////////////////// // The one and only CEssai2App object CEssai2App theApp; extern "C" __declspec(dllexport) int WINAPI Maximum(int a,int b) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); int max; if(a

                          J 1 Reply Last reply
                          0
                          • G Gerald Mercet

                            just for information the C++ code and vba code: //////VBA////////////////////////////////////////////////// Public Declare Function Maximum Lib "D:\essai2\Release\essai2.dll" Alias "_Maximum@8" (ByVal m1 As Long, ByVal m2 As Long) As Long Function test2(m As Long, n As Long) test2 = Maximum(m, n) If test2 = "" Then test2 = 0 Else test2 = test2 End If End Function Sub test22() Cells(5, 5) = Maximum(2, 6) //////C++///////////////////////////////////////////////// / essai2.cpp : Defines the initialization routines for the DLL. // #include "stdafx.h" #include "essai2.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // // Note! // // If this DLL is dynamically linked against the MFC // DLLs, any functions exported from this DLL which // call into MFC must have the AFX_MANAGE_STATE macro // added at the very beginning of the function. // // For example: // // extern "C" BOOL PASCAL EXPORT ExportedFunction() // { // AFX_MANAGE_STATE(AfxGetStaticModuleState()); // // normal function body here // } // // It is very important that this macro appear in each // function, prior to any calls into MFC. This means that // it must appear as the first statement within the // function, even before any object variable declarations // as their constructors may generate calls into the MFC // DLL. // // Please see MFC Technical Notes 33 and 58 for additional // details. // ///////////////////////////////////////////////////////////////////////////// // CEssai2App BEGIN_MESSAGE_MAP(CEssai2App, CWinApp) //{{AFX_MSG_MAP(CEssai2App) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CEssai2App construction CEssai2App::CEssai2App() { // TODO: add construction code here, // Place all significant initialization in InitInstance } ///////////////////////////////////////////////////////////////////////////// // The one and only CEssai2App object CEssai2App theApp; extern "C" __declspec(dllexport) int WINAPI Maximum(int a,int b) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); int max; if(a

                            J Offline
                            J Offline
                            Joaquin M Lopez Munoz
                            wrote on last edited by
                            #26

                            What does "sthg" mean? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                            G 1 Reply Last reply
                            0
                            • J Joaquin M Lopez Munoz

                              What does "sthg" mean? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                              G Offline
                              G Offline
                              Gerald Mercet
                              wrote on last edited by
                              #27

                              sthg=something...

                              1 Reply Last reply
                              0
                              • J Joaquin M Lopez Munoz

                                Et bien? (avec un air d'expectation) Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                                G Offline
                                G Offline
                                Gerald Mercet
                                wrote on last edited by
                                #28

                                Are you here or not? because i'm totally lost...please

                                J 2 Replies Last reply
                                0
                                • G Gerald Mercet

                                  Are you here or not? because i'm totally lost...please

                                  J Offline
                                  J Offline
                                  Joaquin M Lopez Munoz
                                  wrote on last edited by
                                  #29

                                  I posted a message to you directly by email, but it must have gotten lost in its way to your address... Well, your code seems fine to me. As I was saying in that email, if you can afford sending me the whole stuff by email (the MFC project and the Excel sheet), I'll take a look at it this afternoon. Apart from this, you'd be probably better off trying to obtain the help of someone near you with some expertise in this area. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                                  G 1 Reply Last reply
                                  0
                                  • J Joaquin M Lopez Munoz

                                    I posted a message to you directly by email, but it must have gotten lost in its way to your address... Well, your code seems fine to me. As I was saying in that email, if you can afford sending me the whole stuff by email (the MFC project and the Excel sheet), I'll take a look at it this afternoon. Apart from this, you'd be probably better off trying to obtain the help of someone near you with some expertise in this area. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                                    G Offline
                                    G Offline
                                    Gerald Mercet
                                    wrote on last edited by
                                    #30

                                    i've found the solution in the vba references, in fact, in this dialog box i have flagged some specifics option as vc++ debug... and it works now, with exactly the code you submitted me before. So... Now, i could really thank you for your patience. regards gerald:)

                                    1 Reply Last reply
                                    0
                                    • G Gerald Mercet

                                      Are you here or not? because i'm totally lost...please

                                      J Offline
                                      J Offline
                                      Joaquin M Lopez Munoz
                                      wrote on last edited by
                                      #31

                                      Would you be so kind as to passing me that VBA reference you're talking about? I'd like to learn something from this thread also :) Congratulations and good luck with your project. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                                      1 Reply Last reply
                                      0
                                      • G Gerald Mercet

                                        i've done it and it doesn't work yet. What do you think about my way of doing for this dll application perhaps i've forgotten sthg in the procedure? i think that sthg completly stupid have been forgotten, but i don't know what! thanks

                                        C Offline
                                        C Offline
                                        Carlos Antollini
                                        wrote on last edited by
                                        #32

                                        Gerald, please send me your code... Regards Carlos Antollini. Sonork ID 100.10529 cantollini

                                        1 Reply Last reply
                                        0
                                        • G Gerald Mercet

                                          I have tried your suggestion without any success. so in the vba code i've done a simple Sub, which only call the function Maximum and put the result into a excel's cell, as following: /////////////////////////////////////////////////////////// Sub test22() Cells(5, 5) = Maximum(2, 6) End Sub ////////////////////////////////////////////////////////// when i play it, i have the following error message: (sorry but as my excel version is french, the error message is in english) so: "Entry point" Maximum of a dll which cannot be found in D:\essai2\Debug\essai2.dll. Of course after this message, i have checked if the path was correct, and it was!!! so, do you think that i'm unlucky X| X| X|

                                          C Offline
                                          C Offline
                                          Carlos Antollini
                                          wrote on last edited by
                                          #33

                                          Gérald Mercet wrote: "Entry point" Maximum of a dll which cannot be found in D:\essai2\Debug\essai2.dll. THAT IS YOUR PROBLEM... VB is a little fastidious for find functions in a dll....;) You need to declare the EXPORT in the .def file

                                          EXPORTS
                                          @10 Maximum //I put @10, you can put every value

                                          Include the .def file in your project and ready. Regards :-D Carlos Antollini. Sonork ID 100.10529 cantollini

                                          G 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups