User forums > Using Code::Blocks

Issue creating DLL

(1/2) > >>

hopslam:
I am trying to create a DLL in codeblocks, and use it in VB.net, but I have been having issues getting the DLL to work. I have created a very simple DLL to test with, and wondering if anyone would know of any settings or anything else that may be causing the issue.

The cpp file:

--- Code: ---#include "main.h"

// a sample exported function
int DLL_EXPORT SomeFunction()
{
    return 5;
}

--- End code ---

The header file:

--- Code: ---#ifndef __MAIN_H__
#define __MAIN_H__

#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

int DLL_EXPORT SomeFunction();

#ifdef __cplusplus
}
#endif

#endif // __MAIN_H__

--- End code ---

I call the function into VB.net like this:

--- Code: ---Class DLL_Functions
    Public Declare Function SomeFunction Lib "C:\Users\Owner\Desktop\Header Test\test\bin\Debug\test.dll" () As Integer
End Class
--- End code ---

When I go to run the function I get an error: "Unable to load DLL. The specified module could not be found. (Exception from HRESULT: 0x8007007E)"

I have checked just to ensure the file path is correct as well.

oBFusCATed:
Post the full rebuild log.
Can you use depends.exe to inspect your dll?
Do you see the function?
My guess is that C++ name mangling is causing you the trouble.

hopslam:

--- Quote from: oBFusCATed on November 23, 2020, 11:44:09 pm ---Post the full rebuild log.
Can you use depends.exe to inspect your dll?
Do you see the function?
My guess is that C++ name mangling is causing you the trouble.

--- End quote ---

Sorry I somehow missed the reply to the post.

The full build log is:

-------------- Build: Debug in test (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -DBUILD_DLL -g  -c "C:\Users\Owner\Desktop\Header Test\test\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe -shared -Wl,--output-def=bin\Debug\libtest.def -Wl,--out-implib=bin\Debug\libtest.a -Wl,--dll  obj\Debug\main.o  -o bin\Debug\test.dll  -luser32
Output file is bin\Debug\test.dll with size 35.87 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

When I try to use dependency walker I get an error: At least one required implicit or forwarded dependency was not found, and a warning: At least one delay-load dependency module was not found. The problem with that is every API-MS_WIN_CORE dll gives an error.

sodev:
Dependency Walker is kind of broken since Windows 7, it has lots of trouble with this new API related stuff. A better alternative is to use https://github.com/lucasg/Dependencies, it can resolve these dependencies properly.

hopslam:
Ok so that worked a lot better. When using the test DLL, it gives says it cannot find libgcc_s_dw2-1.dll.

Edit: After searching real fast it it seems like just enabling static libgcc and static libstdc++ fixed the issue. Are there any other general settings that are usually good to have enabled?

Navigation

[0] Message Index

[#] Next page

Go to full version