我在让 libsndfile-1.dll 在我的 MSVC 项目中工作时遇到问题。我可以通过调用 sf_command()
加载库并从 dll 检索版本字符串。从我的代码中。但是,我似乎无法得到 sf__open()
返回一个 SNDFILE 指针。
我还注意到我无法获取 fopen()
返回 FILE 指针(也许这是相关的,我认为 sf_open()
使用 fopen()
!?)。
我对 MSVC、C/C++ 和 Windows 都很陌生,所以我可能错过了一些非常明显的东西。
我的 main.cpp 如下所示:
#include <windows.h>
#include <stdio.h>
#include "sndfile.hh"
// create some function pointers to point to the dll function addresses
// I'm winging this a bit. hopefully it's right!? seems to work!
typedef int (*SF_COMMAND)(SNDFILE*, int, void*, int);
typedef SNDFILE* (*SF_OPEN)(const char*, int, SF_INFO*);
int main()
{
// dll handle
HINSTANCE hDLL = NULL;
// create some vars to store the dll funcs in
SF_COMMAND sf_command;
SF_OPEN sf_open;
// load the dll
hDLL = LoadLibrary(L"libsndfile-1.dll");
// check the dll loaded
if( NULL == hDLL )
{
printf("Error, Could not load library \n");
return 1;
}
// get the dll funcs
sf_command = (SF_COMMAND)GetProcAddress(hDLL, "sf_command");
sf_open = (SF_OPEN)GetProcAddress(hDLL, "sf_open");
// check we got the funcs
if(!(sf_command && sf_open)){
printf("Error exporting dll functions \n");
return 2;
}
// all good so far!
// try the first function
char* version_string[sizeof(char*)*4];
int res = sf_command(NULL, SFC_GET_LIB_VERSION, &version_string, sizeof(version_string));
if(res){
// all good!
printf("Version: %s \n", version_string);
}
// now try and create a SNDFILE pointer
SF_INFO info;
SNDFILE* sfp = sf_open("c:\\Godspeed.aif", SFM_READ, &info);
if(sfp){
printf("Hurray! successfully opened the SNDFILE!! \n");
}else{
printf("Doh! couldn't open the SNDFILE!! \n");
// Grr!!
return 3;
}
return 0;
}
项目构建并退出,代码为 3(无法打开文件!(我很确定文件在那里!!))。
当我运行 exe 时,输出为:
Version: libsndfile-1.0.17
Doh! couldn't open the SNDFILE
有人对我哪里出错有什么建议吗?
非常感谢,
乔什。
最佳答案
嗯,我真的应该学会不要在深夜发帖! 今天早上我又进行了一次尝试,并在几分钟内打开了文件。 我的路径全错了(不习惯这些奇怪的 Windows 路径)! 我尝试使用相对路径和宾果游戏! 希望对某人有所帮助!
关于c - 如何在 MSVC 中访问 libsndfile-1.dll 中的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1522989/