无法创建 DLL:获取 DLL "is not a valid Win32 application"
Unable to create DLLs: Getting DLL "is not a valid Win32 application"
正如标题所说,我无法创建一个简单的DLL。 我使用的是VS 2017社区版版本15.8.0。 这是.dll代码:
#include "stdafx.h"
#include "InvWin32App.h"
#include "$StdHdr.h"
void Prc1()
{
printf("ran procedure 1n");
}
这是标头的代码,根据MS的执行方式:
#ifdef INVWIN32APP_EXPORTS
#define INVWIN32APP_API __declspec(dllexport)
#else
#define INVWIN32APP_API __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C" {
#endif
INVWIN32APP_API void Prc1();
#ifdef __cplusplus
}
#endif
以下是驱动程序代码:(更新:驱动程序是一个.exe程序。
#include "pch.h"
#include "InvWin32App.h"
int main()
{
Prc1();
}
没有比这更简单的了。 当我尝试运行代码时,我收到以下错误消息框:
Unable to start program
program name.dll
program name.dll is not
a valid Win32 application
我可以创建.exe程序。 今天早上早些时候,当我运行VS 2017版本15.7.5时,我也遇到了错误。 升级 VS 没有任何好处。 我也试图将这些编译为.c程序,但它没有任何区别。
我在使用 VS 2015 创建.exe程序时遇到了这个问题。 我不记得我做了什么,但问题消失了。 任何帮助将不胜感激。
蒂亚。
右键单击解决方案资源管理器中的项目,该项目是可执行文件的项目,然后单击"设置为启动项目"。
请注意,"不是有效的Win32应用程序"不是编译错误或链接错误,而是您在尝试调试不可执行的内容时收到的消息。
您只能启动可执行文件。可执行文件使用 dll。这些应该是两个单独的项目,具有两组相应的项目设置。
我怀疑你使用的是 32 位 dll。如果您有 64 位 Windows 操作系统,那么您也必须拥有此 dll 的 64 位版本。有时,即使您已经拥有 64 位 dll,它也无法运行,因此请尝试此 dll 的其他版本,即此 dll 的 32 位版本。 除此之外,还要对unicurse.py
文件进行一些小的更改。 PFB 要添加的代码:
import ctypes
pdlib = ctypes.CDLL("pdcurses.dll")
虽然这行代码在某些条件中的某个地方,但放在顶部将帮助您检查 DLL 是否已加载。
对于此时加入队伍的任何一个人,我发现此错误是在您尝试运行32bit dll using a 64bit python
时引起的。
现在,我不会详细介绍为什么这不起作用,因为上面的回复清楚地描述了这一点,但是有2种解决方案。
- 安装和 32 位 python 并使用它来与 dll 通信。
- 使用 msl-loadlib 库文档的进程间通信
我使用了第二步,这似乎更具可持续性。我在下面使用的步骤可以在上面的文档链接中找到。
- 首先是创建一个与 32 位模块通信的服务器模块
#server.py
from msl.loadlib import Server32
class Server(Server32):
# the init takes mandatory host and port as arguments
def __init__(self, host, port, **kwargs):
# using windll since this application is being run in windows, other options such as cdll exists
# this assumes that the dll file is in the same directory as this file
super(Server, self).__init__('tresdlib.dll', 'windll', host, port)
# define a function that is to be called with the required arguments
def fsl_command(self, com, doc):
#the server32 exposes the loaded dll as lib, which you can then use to call the dll functions and pass the required arguments
return self.lib.FSL_Command(com,doc)
- 然后我们创建一个客户端模块,将python请求发送到服务器模块
#client.py
from msl.loadlib import Client64
class Client(Client64):
def __init__(self):
# pass the server file we just created in module32=, the host am using is localhost, leave port as none for self assigning
super(Client, self).__init__(module32='server', host="127.0.0.1", port=None)
# define a function that calls the an existing server function and passes the args
def fsl_command(self, com, doc):
return self.request32('fsl_command', com, doc)
我们将在终端中运行它,但您可以选择在另一个应用程序中调用
>>> from client import Client
>>> c = Client()
>>> c.fsl_command(arg1,arg2)
- 挂起和取消挂起一个文件DLL
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 导入库可以跨dll版本工作吗
- 从C++dll访问C#中的一行主要参数
- 链接到自行创建的dll失败
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- 在调用FreeLibrary后,释放动态链接到具有相同版本的CRT堆的DLL的内存
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- C++:将外部库链接到dll库
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 不同的Visual Studio版本中缺少.dll
- 从DLL中删除类的实例
- 如何包装第三方DLL在R中使用
- 使用c#访问c++dll中带有char*参数的函数时发生AccessViolationException
- 系统.将数组移交给c#中动态加载的c++DLL时发生AccessViolationException
- 无法创建 DLL:获取 DLL "is not a valid Win32 application"
- C++ DLL 运行时错误"abc.dll is not a valid WIN32 application" 。请帮助解决这个问题
- 在 Unity 中使用 x64 c++ dll 可以"Is not a valid Win32 application error"
- JNI C++ DLL - 'UnsatisfiedLinkError: %1 is not a valid Win32 application'