GetProcAddress cannot find my functions

I created a DLL with the "render ()" function, and I want to load it dynamically into my application, but GetProcAddress cannot find it. Here is the DLL.h:

#ifdef D3D_API_EXPORTS
#define D3D_API_API __declspec(dllexport)
#else
#define D3D_API_API __declspec(dllimport)
#endif

D3D_API_API void render();

And here is the DLL.cpp:

#include "stdafx.h"
#include "D3D_API.h"
#include <iostream>

D3D_API_API void render()
{
    std::cout << "method called." << std::endl;
}

Here is the application that is trying to use this function:

#include "stdafx.h"
#include <windows.h>
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
    HINSTANCE myDLL = LoadLibrary( L"D3D_API.dll" );

    if (myDLL == NULL) {
        std::cerr << "Loading of D3D_API.dll failed!" << std::endl;
    }

    typedef void (WINAPI *render_t)();

    render_t render = (render_t)GetProcAddress( myDLL, "render" );

    if (render == NULL) {
        std::cerr << "render() not found in .dll!" << std::endl;
    }
    return 0;
}

My goal is to create a 3D engine that supports both D3D and OpenGL through their own .DLL using a unified API. I looked at the .dll in notepad and the line "render" appeared.

+3
source share
1 answer

++ (- .cpp), ++ name mangling . . - :

extern "C" D3D_API_API void render();

expexted.

+9

Source: https://habr.com/ru/post/1740352/


All Articles