a simply question about dlls
-
Hi, it's the first time i try to create a dll application which could be used from excel. So i try to do it by creating a MFC dynamically linked dll, where i put a simply code for a simply function: ///////////////////////////////////////////////////////////////////////////// // 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
-
Hi, it's the first time i try to create a dll application which could be used from excel. So i try to do it by creating a MFC dynamically linked dll, where i put a simply code for a simply function: ///////////////////////////////////////////////////////////////////////////// // 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
I guess you forgot the
__stdcall
(akaWINAPI
) specifier. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
I guess you forgot the
__stdcall
(akaWINAPI
) specifier. Joaquín M López Muñoz Telefónica, Investigación y Desarrollocould you more explicit? because i'm a beginner in this kind of application... X|
-
could you more explicit? because i'm a beginner in this kind of application... X|
Of course. Define your function as follows:
extern "C" __declspec(dllexport) int WINAPI Maximum(int a,int b)
If you're curious about that
WINAPI
thing, have a look at Nemanja Trifunovic's Calling Conventions Demystified Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
Of course. Define your function as follows:
extern "C" __declspec(dllexport) int WINAPI Maximum(int a,int b)
If you're curious about that
WINAPI
thing, have a look at Nemanja Trifunovic's Calling Conventions Demystified Joaquín M López Muñoz Telefónica, Investigación y DesarrolloI tried to do it, and it didn't work, so do you have any other suggestion, because i'm lost:confused: X| :confused: X|
-
I tried to do it, and it didn't work, so do you have any other suggestion, because i'm lost:confused: X| :confused: X|
Try to add the .def file, in it you can define the function to export. Sometimes VB can't access to the function. How you are declaring the function un VB or vba?? Regards... Carlos Antollini. Sonork ID 100.10529 cantollini "There is an old saying that if a million monkeys typed on a million keyboards for a million years, eventually all the works of Shakespeare would be produced. Now, thanks to Usenet, we know this is not true."
-
Try to add the .def file, in it you can define the function to export. Sometimes VB can't access to the function. How you are declaring the function un VB or vba?? Regards... Carlos Antollini. Sonork ID 100.10529 cantollini "There is an old saying that if a million monkeys typed on a million keyboards for a million years, eventually all the works of Shakespeare would be produced. Now, thanks to Usenet, we know this is not true."
i do it in vba. does it change sthg for the first thing you said? regards
-
i do it in vba. does it change sthg for the first thing you said? regards
I need to know how you are declaring the function in vba..... Regards Carlos Antollini. Sonork ID 100.10529 cantollini
-
I need to know how you are declaring the function in vba..... Regards Carlos Antollini. Sonork ID 100.10529 cantollini
After the definition in VC++ i put the following code in vba: Public Declare Function Maximun Lib "D:\essai2\Debug\essai2.dll"(byval a as integer,byval b as integer) as integer I have put it into a simple module, without anything else. So, if you need of information on the code in "C", you could look at my first post. thanks
-
After the definition in VC++ i put the following code in vba: Public Declare Function Maximun Lib "D:\essai2\Debug\essai2.dll"(byval a as integer,byval b as integer) as integer I have put it into a simple module, without anything else. So, if you need of information on the code in "C", you could look at my first post. thanks
Gérald Mercet wrote: Public Declare Function Maximun Lib "D:\essai2\Debug\essai2.dll"(byval a as integer,byval b as integer) as integer Change the Integer by Long... Regards.... Carlos Antollini. Sonork ID 100.10529 cantollini
-
After the definition in VC++ i put the following code in vba: Public Declare Function Maximun Lib "D:\essai2\Debug\essai2.dll"(byval a as integer,byval b as integer) as integer I have put it into a simple module, without anything else. So, if you need of information on the code in "C", you could look at my first post. thanks
I've just noticed you named the function
Maximum
in your C++ file andMaximun
in your VB app. Is this a typo in the post or could it be the root of the problem? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
Gérald Mercet wrote: Public Declare Function Maximun Lib "D:\essai2\Debug\essai2.dll"(byval a as integer,byval b as integer) as integer Change the Integer by Long... Regards.... Carlos Antollini. Sonork ID 100.10529 cantollini
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
-
I've just noticed you named the function
Maximum
in your C++ file andMaximun
in your VB app. Is this a typo in the post or could it be the root of the problem? Joaquín M López Muñoz Telefónica, Investigación y Desarrolloyou 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:
-
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:
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 -
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 DesarrolloIn 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
-
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
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 theMaximun
/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 -
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 theMaximun
/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 DesarrolloOk, 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
-
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
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
-
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
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
-
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
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