1

Topic: How to create on VBA object of a class which is written on With ++ and it is connected as DLL?

There is a test code on a C ++ in which function MyFun001 and a class MyClass which contains function CFun001 and a variable CVal is described. The code is compiled in library DLL (the Visual Studio 2015 is used).
The described test project With ++ contains two files: source.cpp and DefFile.def .
File DefFile.def is necessary, as I understand to specify to the compiler to create in DLL entry points for functions (that the def-file was considered by the compiler, in project adjustments it is necessary to fill out a name of this file - see more in detail here ).
The content of the code With ++:
source.cpp:

//class and function titles
int _stdcall MyFun001 (int);
class MyClass
{
public:
MyClass ();
int CFun001 (int);
private:
int CVal;
};
//class and function implementation
int _stdcall MyFun001 (int x)
{
MyClass mc;
return mc. CFun001 (x);
}
MyClass:: MyClass ()
{
CVal = 3;
}
int MyClass:: CFun001 (int y)
{
return CVal * y;
}

DefFile.def:

LIBRARY "source"
EXPORTS
MyFun001

Code VBA in MS Excel 2010:

Private Declare PtrSafe Function MyFun001 Lib "D: \_ CPP\TestLib\TestLib001\Debug\TestLib001.dll" _
(ByVal x As Long) As Long
Private Sub TestMyDLL ()
x& = 4
Debug. Print MyFun001 (x)
Dim o1 As New MyClass
Debug. Print o1.CFun001 (x)
End Sub

Function MyFun001 from DLL in VBA is launched and correctly works. But how to create object of a class MyClass I do not understand, the resulted code causes an error " User-defined type not defined ". In a file.def a class it is impossible to describe just as functions, and in VBA it is impossible to declare a class (Declare Class...).

2

Re: How to create on VBA object of a class which is written on With ++ and it is connected as DLL?

That worked Dim o1 As New MyClass, the library should be com-library, that is support interfaces IUnknown and IDispatch, and still it should be registered in the register or have the manifesto.
https://msdn.microsoft.com/en-us/library/ms680573.aspx

3

Re: How to create on VBA object of a class which is written on With ++ and it is connected as DLL?

https://yandex.ru/search/? text= com on c &lr=213

4

Re: How to create on VBA object of a class which is written on With ++ and it is connected as DLL?

Antonariy, and whether there is a possibility to create objects without registration DLL?
It is supposed that file Excel + file DLL will be used on different computers by different users (including ). Registration DLL will or demand each time of my presence, or can be accompanied by difficulties which were to be avoided.

5

Re: How to create on VBA object of a class which is written on With ++ and it is connected as DLL?

rothor wrote:

Antonariy, and whether there is a possibility to create objects without registration DLL?

the manifesto.