среда, 11 мая 2016 г.

Подключение DLL (Си) к VBA


 Код на СИ

/// Файл main.h
#ifndef __MAIN_H__
#define __MAIN_H__


#include <windows.h>
#include <stdint.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

void __stdcall DLL_EXPORT SomeFunction(const LPCSTR sometext);

#ifdef __cplusplus
}
#endif

#endif // __MAIN_H__


/// Файл main.c
#include "main.h"

// a sample exported function
void __stdcall DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
    MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}


'Код в VBA модуле:
Declare Sub SomeFunction Lib "dllTestVBA.dll" _
Alias "SomeFunction@4" (ByVal msg As String)

' SomeFunction@4 - это смотреть в dllTestVBA.def
'
Sub tt()
     SomeFunction "gfgfg"
End Sub