0

  我无法让 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

有人对我哪里出错有任何建议吗?

非常感谢,
乔希。

4

1 回答 1

0

嗯,我真的应该学会不要在深夜发帖!今天早上我又尝试了一次,并在几分钟内打开了文件。我的路径都错了(不习惯这些奇怪的 Windows 路径)!我尝试使用相对路径和宾果游戏!希望对某人有所帮助!

于 2009-10-06T08:58:46.960 回答