8000 加载动态库 (loadlibrary) · Issue #61 · holdyounger/ScopeBlog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
加载动态库 (loadlibrary) #61
Open
@holdyounger

Description

@holdyounger

加载动态库 (loadlibrary)

[toc]

加载

> using的用法参考 使用using起别名

#include <iostream>
#include <windows.h>
#include "PipeIPC/PipeIPC.h"

int main()
{
    std::cout << "--- DLL Test ---\n";

    HINSTANCE hDLL; // Handle to DLL
    using Face = int * (*)(int,int);

    hDLL = LoadLibrary(L"mydll.dll");
     if (hDLL != NULL)
    {
        Face faceSum = (Face)GetProcAddress(hDLL,
            "mySum");

        if (!faceSum)
        {
            // handle the error
            FreeLibrary(hDLL);
            return 0;
        }
        else
        {
            // call the function
           	faceSum(1,1);
        }
    }
    return 0;
}

生成动态库

dllmain.cpp

#ifdef __cplusplus
extern "C"
{
#endif	 

#define MYIMAPI extern "C" __declspec(dllimport)

#define MYEXAPI extern "C" __declspec(dllexport)

#ifdef __cplusplus
}
#endif

MYEXAPI int Add(int numa, int numb)
{
    return numa + numb;
}

MYEXAPI int Sub(int numa, int numb)
{
	return (numa - numb);
}

blog link 加载动态库 (loadlibrary)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0