0

I am trying to run the following code using Visual Studio Code 2019. The function is in the file that I have.

I have added this file to the Additional Dependencies section of the project and also set the Library Directories folder to the location where I have the .lib saved.

Despite all this I still get

Why is this happening?

user3702643
  • 1,465
  • 5
  • 21
  • 48
  • 2
    `extern "C" __declspec(dllexport) int Run_RsbbDec(const char* Input_File, int vbr_en, int bitrate, char* ErrMsg);` Are you building a `dll` or using one? export means your code is a `dll` and you provide the implementation of this function that some other dll or application will use. – drescherjm Nov 07 '19 at 12:53
  • I don't understand what you mean. I was given a .lib file and a .dll file. All I want to do is use the Run_RsbbDec function @drescherjm – user3702643 Nov 07 '19 at 12:56
  • 1
    The `.lib` is probably an import library for the `.dll` you likely need `dllimport` instead of `dllexport`. Although normally you have a header with the dll that provides this. – drescherjm Nov 07 '19 at 12:57
  • `dllexport` is used when creating a DLL to tell that the symbol should be exported from the DLL. If you want to use a function from a DLL then you need **`dllimport`**. – Some programmer dude Nov 07 '19 at 12:57
  • Thank you for the replies. I just tried dllimport. I still got the same linker error. – user3702643 Nov 07 '19 at 12:59
  • I expect you made some mistake in this part: ***I have added this file to the Additional Dependencies section of the project and also set the Library Directories folder to the location where I have the .lib saved.*** – drescherjm Nov 07 '19 at 13:00
  • @drescherjm I will double check – user3702643 Nov 07 '19 at 13:08
  • @drescherjm I do have an exe that is named Run_RsbbDec.exe. Do I need to link that to the project? – user3702643 Nov 07 '19 at 13:17
  • Are you sure that you adjusted the linker settings for the configuration of the build ? (say Release for both) –  Nov 07 '19 at 13:20
  • 1
    Declaring this function yourself is risky. You could easily get the calling convention wrong. Or the name, you can't trust a programmer that thinks "RsbbDec" is a good function name. Get back on the phone and demand a .h file. If nobody picks up then at least run Dumpbin.exe /exports on the DLL. – Hans Passant Nov 07 '19 at 13:20
  • ***I do have an exe that is named Run_RsbbDec.exe. Do I need to link that to the project?*** If this is native `c++` you don't link executables onlt static libraries or import libraries. – drescherjm Nov 07 '19 at 13:26

1 Answers1

2
extern "C" __declspec(dllexport) int Run_RsbbDec(const char* Input_File, int vbr_en, int bitrate, char* ErrMsg);

Change this to:

extern "C" __declspec(dllimport) int Run_RsbbDec(const char* Input_File, int vbr_en, int bitrate, char* ErrMsg);

You should change this function to dllimport since you want to import it in your code from the library. You use dllexport when writing the library stating that the function will be exported to be used when the library is used somewhere else.

Also, if you would like your code to run after you have compiled it you need to copy TRSCompress.dll to where the you have compiled your code.

And make sure that you are implementing the right function. Is the function defined in the same way in the library? Does it return int and has input of those parameters?

Filip
  • 155
  • 10
  • I have done everything you said which makes me believe that the function might not be properly defined. Is there anyway to check? I did not create the library. This sample code was given to me by the creator of the library though. – user3702643 Nov 07 '19 at 13:15
  • Like I said above, I do have an exe that is named Run_RsbbDec.exe. Do I need to link that to the project? Could the function be inside there? – user3702643 Nov 07 '19 at 13:17
  • 1
    Yes, open visual studio developer console (cmd), and you can use dumpbin /exports PATH_TO_LIB_FILE. It will print out the exports. Using this you can check what functions the library exports. However, as stated here https://stackoverflow.com/questions/305287/how-to-see-the-contents-of-windows-library-lib I don't think you can check the input and output parameters of the function by using solely the .lib alone. Does the library come with a header that defines the functions? – Filip Nov 07 '19 at 13:18
  • So I realised that the lib does not even export the function that the developer said it exports, and I realise now how difficult it is to work without a .h file. I think I have to just go back and talk to that developer. – user3702643 Nov 07 '19 at 13:31