~ruther/csharp-dll-injector

ref: 322bb9b0c6137a531527a5833c296838882b74f1 csharp-dll-injector/examples/cpp/CppLibrary/dllmain.cpp -rw-r--r-- 1.2 KiB
322bb9b0 — František Boháček Add Calculation result return examples 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include <iostream>

BOOL APIENTRY DllMain(HMODULE hModule,
    DWORD  ul_reason_for_call,
    LPVOID lpReserved
)
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

#pragma pack(push, 1)
struct AdditionParams
{
    int first;
    int second;
};
#pragma pack(pop)

#pragma pack(push, 1)
struct MyFunctionParams
{
    char* data;
    int number;
};
#pragma pack(pop)

int __declspec(dllexport) Main(void)
{
    AllocConsole();
    freopen("CONOUT$", "w", stdout);

    std::cout << "Hello from cpp library dllmain::Main!" << std::endl;

    return 1;
}

int __declspec(dllexport) Add(AdditionParams* params)
{
    std::cout << "Performing addition of numbers " << params->first << " and " << params->second << std::endl;

    return params->first + params->second;
}

bool __declspec(dllexport) MyFunction(MyFunctionParams* params)
{
    std::cout << "Hello from dllmain::MyFunction" << std::endl;
    std::cout << "  Data: " << params->data << std::endl;
    std::cout << "  Number: " << params->number << std::endl;

    return true;
}
Do not follow this link