comment compiler une fonction écrite en c++ dll en utilisant code blocks dans VBA excel
Bonsoir tout le monde
SVP j'ai vraiment besoin votre aide
c'est la première fois que j'essaie de créer une c++ dll pour faire de traitement et retourner le résultat en vba excel.
donc j'ai créée une c++ dll en utilisant code blocks,et j'ai essayé de faire l'appel de cette dll sur vba excel mais une erreur s'affiche :
runtime error 48 :
file not found
""C:\Users\younes\Desktop\vba-c++\dllpr\bin\Release\dllpr.dll"
code main.cpp:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include "main.h"
// a sample exported function
DLL_EXPORT int __stdcall carre(int chiffre)
{
return chiffre*chiffre;
}
extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// attach to process
// return FALSE to fail DLL load
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
} |
code main.h :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include <windows.h>
/* To use this exported function of dll, include this header
* in your project.
*/
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
DLL_EXPORT int __stdcall carre(int chiffre);
#ifdef __cplusplus
}
#endif
#endif // __MAIN_H__ |
code VBA :
Code:
1 2 3 4 5 6 7 8 9
|
Option Explicit
Public Declare PtrSafe Function carre Lib "C:\Users\younes\Desktop\vba-c++\dllpr\bin\Release\dllpr.dll" (ByVal chiffre As Integer) As Integer
Sub test()
MsgBox carre(10)
End Sub |
je serais très reconnaissant pour votre aide!
merciii d'avance