내 MSVC 프로젝트에서 libsndfile-1.dll이 작동하는 데 문제가 있습니다. 라이브러리를로드하고 내 코드에서 sf_command()
을 호출하여 dll에서 버전 문자열을 검색 할 수 있습니다. 그러나 sf__open()
SNDFILE 포인터를 반환 할 수 없습니다.MSVC에서 libsndfile-1.dll의 함수에 어떻게 액세스합니까?
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
사람이 어디 잘못된거야에 관한 어떤 제안이 있습니까?
많은 감사,
Josh.