我正在尝试在c#中导入dll c ++ dll,但系统显示异常
System.EntryPointNotFoundException:'无法在DLL'D:\ project \ RunningProcessDll \ Debug \ RunningProcessDll .dll'中找到名为'0x00011091'的入口点。'
这是 dllmain.cpp 文件
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "dllmain.h"
UINT PID_GetProcessId() {
TCHAR szProcessName[MAX_PATH];
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded);
cProcesses = cbNeeded / sizeof(DWORD);
for (i = 0; i < cProcesses; i++) {
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, aProcesses[i]);
if (NULL != hProcess)
{
HMODULE hMod;
DWORD cbNeeded;
if (EnumProcessModules(hProcess, &hMod, sizeof(hMod),
&cbNeeded))
{
GetModuleBaseName(hProcess, hMod, szProcessName,
sizeof(szProcessName) / sizeof(TCHAR));
}
}
return aProcesses[i];
}
}
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;
}
这是 dllmain.h 文件
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <tlhelp32.h>
#include <Psapi.h>
extern "C" __declspec(dllexport) UINT PID_GetProcessId();
这是c#wpf应用程序文件
[DllImport(@"D:\\project\\RunningProcessDll\\Debug\\RunningProcessDll.dll",
EntryPoint ="0x00011091", CallingConvention =
CallingConvention.Cdecl)]
public static extern uint PID_GetProcessID();
int a = size();
public MainWindow()
{
InitializeComponent();
for (int i = 0; i <= a; i++)
{
dg.Items.Add(new Process()
{
ID = PID_GetProcessID().ToString(),
});
}
我经历了多个网站,但问题没有解决。 我甚至通过依赖包装器检查了函数的入口点,然后在dllImport中添加它,但是这个异常仍然发生