简体   繁体   English

创建并将静态库链接到Visual Basic Windows Forms应用程序

[英]Creating and linking a static library to visual basic windows forms application

I have created two programs in Visual Studio2010. 我在Visual Studio2010中创建了两个程序。

One is a visual basic windows forms application(user frontend) which prompts the user to select a file path (.bin file). 一个是可视化的基本Windows窗体应用程序(用户前端),它提示用户选择文件路径(.bin文件)。 The second program is a Visual Studio C++ Application, which has a ReadFile() function , which reads the contents of the binary file and performs some mathematical calculations. 第二个程序是Visual Studio C ++应用程序,它具有ReadFile()函数 ,该函数读取二进制文件的内容并执行一些数学计算。

I want to generate a static library(.lib) from the second program and link it with the first program (user frontend). 我想从第二个程序生成一个静态库(.lib),并将其与第一个程序(用户前端)链接。 The user frontend program must be able to pass the file path to the ReadFile() function in the static library. 用户前端程序必须能够将文件路径传递给静态库中的ReadFile()函数

I have created both the programs separately, but finding it difficult to create the static library and link it with the user frontend. 我已经分别创建了这两个程序,但是发现很难创建静态库并将其与用户前端链接。 How do i go about this ?? 我该怎么办?

PS: This may sound as stupid, but my aim is to learn how to create and link a static library to windows forms application. PS:这听起来很愚蠢,但是我的目的是学习如何创建静态库并将其链接到Windows Forms应用程序。

The user front end application which prompts the user to select the file. 提示用户选择文件的用户前端应用程序。

Do the following steps To create a static library project: 请执行以下步骤以创建静态库项目:

  1. On the menu bar, choose File, New, Project. 在菜单栏上,选择“文件”,“新建”,“项目”。
  2. In the left pane of the New Project dialog box, expand Installed, Templates, Visual C++, and then select Win32. 在“新建项目”对话框的左窗格中,展开“已安装”,“模板”,“ Visual C ++”,然后选择“ Win32”。
  3. In the center pane, select Win32 Console Application. 在中央窗格中,选择“ Win32控制台应用程序”。
  4. Specify a name for the project—for example, MathFuncsLib—in the Name box. 在“名称”框中指定项目的名称,例如MathFuncsLib。 Specify a name for the solution—for example, StaticLibrary—in the Solution Name box. 在“解决方案名称”框中为解决方案指定一个名称,例如StaticLibrary。 Choose the OK button. 选择确定按钮。
  5. On the Overview page of the Win32 Application Wizard dialog box, choose the Next button. 在“ Win32应用程序向导”对话框的“概述”页面上,选择“下一步”按钮。
  6. On the Application Settings page, under Application type, select Static library. 在“应用程序设置”页上的“应用程序类型”下,选择“静态库”。
  7. On the Application Settings page, under Additional options, clear the Precompiled header check box. 在“应用程序设置”页上的“其他选项”下,清除“预编译头”复选框。
  8. Choose the Finish button to create the project. 选择完成按钮以创建项目。

To create a C++ console app that references the static library 创建引用静态库的C ++控制台应用程序

  1. On the menu bar, choose File, New, Project. 在菜单栏上,选择“文件”,“新建”,“项目”。
  2. In the left pane, under Visual C++, select Win32. 在左窗格中,在Visual C ++下,选择Win32。
  3. In the center pane, select Win32 Console Application. 在中央窗格中,选择“ Win32控制台应用程序”。
  4. Specify a name for the project—for example, MyExecRefsLib—in the Name box. 在“名称”框中指定项目的名称,例如MyExecRefsLib。 In the drop-down list next to Solution, select Add to Solution. 在解决方案旁边的下拉列表中,选择添加到解决方案。 This adds the new project to the solution that contains the static library. 这会将新项目添加到包含静态库的解决方案中。 Choose the OK button. 选择确定按钮。
  5. On the Overview page of the Win32 Application Wizard dialog box, choose the Next button. 在“ Win32应用程序向导”对话框的“概述”页面上,选择“下一步”按钮。
  6. On the Application Settings page, under Application type, select Console application. 在“应用程序设置”页上的“应用程序类型”下,选择“控制台应用程序”。
  7. On the Application Settings page, under Additional options, clear the Precompiled header check box. 在“应用程序设置”页上的“其他选项”下,清除“预编译头”复选框。
  8. Choose the Finish button to create the project. 选择完成按钮以创建项目。

Source: https://msdn.microsoft.com/en-us/library/ms235627.aspx 来源: https : //msdn.microsoft.com/en-us/library/ms235627.aspx

You can see additional info in the link above, how to use the code in your project. 您可以在上面的链接中看到其他信息,以及如何在项目中使用代码。

Update following question in comment : 更新以下评论中的问题

Right click on your project in the solution explorer and then click on Properties . 在解决方案资源管理器中右键单击您的项目,然后单击“ 属性”

Next open Configuration Properties and then Linker . 接下来,打开“ 配置属性”,然后打开“ 链接器”

Now you want to add the folder you have the Allegro libraries in to Additional Library Directories, 现在,您要将Allegro库所在的文件夹添加到“其他库目录”中,

Linker -> Input you'll add the actual library files under Additional Dependencies . 链接器->输入,您将在“ 其他依赖项”下添加实际的库文件。

For the Header Files you'll also want to include their directories under C/C++ -> Additional Include Directories. 对于头文件,您还希望将其目录包括在C / C ++->其他包含目录下。

Have a copy of your lib file in your main project folder, and done 在主项目文件夹中有一个lib文件的副本,并完成

I hope it supports your question. 希望它支持您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM