很抱歉这个非常简单的问题,找不到谷歌回答.
这是声明语法:
__declspec(align(16)) float rF[4];
__declspec(align(16)) float gF[4];
__declspec(align(16)) float bF[4];
Run Code Online (Sandbox Code Playgroud)
相当于:
__declspec(align(16)) float rF[4], gF[4], bF[4];
Run Code Online (Sandbox Code Playgroud)
或者只有第一个变量在后一种语法中对齐?
如果重要,那么这些是全局方法中的局部变量.
尝试使用 gcc 编译一个用 C 编写的简单 DLL。
尝试遵循许多教程,但即使我将文件精简到最基本的内容,也无法编译它。
test_dll.c
#include <stdio.h>
__declspec(dllexport) int __stdcall hello() {
printf ("Hello World!\n");
}
Run Code Online (Sandbox Code Playgroud)
尝试使用命令编译它
gcc -c test_dll.c
Run Code Online (Sandbox Code Playgroud)
失败,得到这个输出
test_dll.c: In function '__declspec':
test_dll.c:3:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'hello'
__declspec(dllexport) int __stdcall hello() {
^
test_dll.c:5:1: error: expected '{' at end of input
}
^
Run Code Online (Sandbox Code Playgroud)
海湾合作委员会版本
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
Run Code Online (Sandbox Code Playgroud) 有没有办法使用一个苗条的#define将难看的"extern \"C \"__ declspec(dllexport)"转换成一个迷人的术语"DLL".
这就是:
#define DLL "extern "C" __declspec(dllexport)"
Run Code Online (Sandbox Code Playgroud)
当然,问题是C周围的嵌入式引号.
我有以下代码,我试图从我的DLL导出一个名为"Interface_API"的函数.
#ifdef INTERFACEDLL_EXPORTS
#define UserApp_API __declspec(dllexport);
#else
#define UserApp_API __declspec(dllimport);
#endif
UserApp_API int Interface_API(int *, int *, int *);
Run Code Online (Sandbox Code Playgroud)
当我编译此代码时,它会发出以下警告,并且该函数未导出.
warning C4091: ' __declspec(dllexport)' : ignored on left of 'int' when no variable is declared
Run Code Online (Sandbox Code Playgroud)
当我更改下面给出的声明时,我没有得到警告,它正确导出.
__declspec(dllexport) int Interface_API(int *, int *, int *);
Run Code Online (Sandbox Code Playgroud)
我有点困惑,因为我已经在不同的DLL中使用它,它工作正常.任何线索?
我正在编写一个 C++ 程序,它在运行时动态加载一个 dll 并在该 dll 中调用一个函数。那工作正常,但现在我想从 dll 中调用在我的 C++ 程序中定义的函数。
我的 main.cpp 看起来像这样:
#include <Windows.h>
#include <iostream>
typedef void(*callC)(int);
int main()
{
HINSTANCE dllHandle = LoadLibrary("D:\Libraries\lib.dll");
callC func = (callC)GetProcAddress(dllHandle, "callC");
func(42);
FreeLibrary(dllHandle);
}
// I want to call this function from my dll
void callableFromDll(){
}
Run Code Online (Sandbox Code Playgroud)
被访问的dll部分是用C写的,如下所示:
#include <stdio.h>
void callC(int);
void callC(int i){
print(i);
// Call the C++ function
//callableFromDll();
}
Run Code Online (Sandbox Code Playgroud)
我已经阅读了__declspec(dllimport)
和__declspec(dllexport)
属性,但我对 C++ 真的很陌生,不确定这些是否正确使用,如果是,如何使用它们。