Repository navigation
Trouble help
For the use of the dynamic link library, we take into account that the .dll file can be next to our executable or in another location, in our case the library is located in the System32 folder.
NOTE: The calling convention __Fastcall is not supported in C # of 32bits, for more information check the reference of the official Microsoft page here.
1. Error: In C # when loading the 32-bit library of type calling convention __stdcall gives an error “Cannot find entry point 'function_Name' in DLL”
Solution: It is solved with the declaration of the calling convention and the name of the corresponding function, check the names of the functions according to the calling convention here.
Example for the function "openMemory"
[DllImport (dllPath, EntryPoint = "openMemory@8", CallingConvention = CallingConvention.StdCall)]`
static extern int openMemory (String memoryName, int typeCode);This is due to an erroneous equivalence, in the library we use the Int type but in Excel we must specify in the call to the function of the .dll that the value is of type Long.
Example for the function "getInt"
In this function both the memory position and the return value are of type Int, but in Excel we must declare as Long (Especially when we work with values of a cell, if we directly send the integer value it could work by declaring Integer in the function , but to avoid problems it is recommended to declare as Long)
X86
Public Declare Function getInt Lib "C:\Windows\SysNative\smClient.dll" Alias "getInt@8" _
(ByVal namMemory As String, ByVal position As Long) As LongX64
Public Declare PtrSafe Function getInt Lib "C:\Windows\SysNative\smClient.dll" _
(ByVal namMemory As String, ByVal position As Long) As LongSolution: You must specify the name of the function with the decorator after the keyword Alias.
Example with the function "setFloat"
Public Declare Sub setFloat Lib "C:\Windows\SysNative\smClient.dll" Alias "setFloat@12" _
(ByVal namMemory As String, ByVal position As Long, ByVal value As Single)Solution: Although it is a very generic error that can have many reasons, one reason may be that functions that have no return should be declared as sub, not as Function, and when we want to call them, we use the reserved word 'call'.
Example of a function that has a return value, is declared as "function"
Public Declare Function getFloat Lib "C:\Windows\SysNative\smClient.dll" Alias "getFloat@8" _
(ByVal namMemory As String, ByVal position As Long) As SingleExample of a function that has no return value, is declared as "sub"
Public Declare Sub setFloat Lib "C:\Windows\SysNative\smClient.dll" Alias "setFloat@12" _
(ByVal namMemory As String, ByVal position As Long, ByVal value As Single)Example of a function call without return "sub"
Call setFloat(memFloatName, position, valueFloat)Excel 32bits gives an error when using libraries generated with calling convention of type __cdecl or __fastcall.
There is no solution - 32-bit Excel only supports 32-bit libraries created with the calling conventions __stdcall.
For more information you can consult the official documentation here and here
Although there are many reasons for this type of behavior, we can list a couple of them.
- This can happen because we declare that the function inside the library will receive an Integer type parameter and we are taking an integer value from a cell and sending it.
Solution - Although in the library the parameter is declared as Int, in Excel we declare that the parameter is of type Long. (Similar to error number 1).
- In the library we have a parameter of type pointer char (char * variable), within Excel we define a variable type 'Dim retString As String' but when it is sent to the library it freezes and Excel closes.
Solution - the variable declared as String within Excel must be initialized or declare the size of the String variable.
Dim retString As String * 13#Errors in the use of DLL in C and C ++
All examples such as client library and the Administration Panel have code documentation in case you want to check the code or adapt it to your needs.