无法创建DLL:获取DLL“不是有效的Win32应用程序"; [英] Unable to create DLLs: Getting DLL "is not a valid Win32 application"

查看:573
本文介绍了无法创建DLL:获取DLL“不是有效的Win32应用程序";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,我无法创建一个简单的DLL.我正在使用VS 2017 Community Edition版本15.8.0.这是.dll代码:

As the title says, I can't create a simple DLL. I'm using VS 2017 Community Edition Version 15.8.0. Here is the .dll code:

#include "stdafx.h"
#include "InvWin32App.h"

#include "$StdHdr.h"

void Prc1()
{
    printf("ran procedure 1\n");
}

以下是按MS方式执行的标头代码:

Here is the code for the header, per the MS way to do things:

#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程序.)

Here is the driver code: (Update: The driver program is an .exe program.)

#include "pch.h"
#include "InvWin32App.h"

int main()
{
    Prc1();
}

没有比这更简单的了.当我尝试运行代码时,出现以下错误消息框:

It can't get any simpler than this. I get the following error message box when I try to run the code:

Unable to start program
program name.dll
program name.dll is not
a valid Win32 application

我可以创建.exe程序.今天早上我在运行VS 2017版本15.7.5时也遇到了错误.升级VS没有任何好处.我也尝试将它们编译为.c程序,但没有任何区别.

I can create .exe programs okay. I also got the error earlier this morning when I was running VS 2017 Version 15.7.5. Upgrading VS didn't do any good. I also tried to compile these as .c programs, but it didn't make any difference.

我有几次使用VS 2015创建.exe程序时遇到此问题.我不记得自己做了什么,但是问题消失了.任何帮助将不胜感激.

I had this problem on a couple occasions creating .exe programs using VS 2015. I don't recall what I did, but the problem disappeared. Any help would be appreciated.

TIA.

推荐答案

在解决方案资源管理器中的可执行项目所在的项目上单击鼠标右键,然后单击设置为启动项目".

Right click the project in your solution explorer that is the project for the executable and click "Set as startup project."

请注意,不是有效的Win32应用程序"不是编译错误或链接错误,它是您尝试调试不可执行的内容时收到的消息.

Note that "is not a valid Win32 application" is not a compile error or a link error, it is the message you get when you tried to debug something that is not executable.

您只能启动可执行文件.可执行文件消耗dll.这些应该是两个单独的项目,具有两组相应的项目设置.

You can only start executables. Executables consume dlls. These should be two seperate projects with two sets of corresponding project settings.

这篇关于无法创建DLL:获取DLL“不是有效的Win32应用程序";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆