1

How does one use the SLOpen() function from slpublic.h in the Windows API?

Update

usr@DESKTOP-xxxxx  /c/users/usr/Desktop
$ cat main.cpp
#include <cstdio>
#include <windows.h>
#include <slpublic.h>

int main()
{
        printf("Hello world\n");
        HSLC ptr;
        SLOpen(&ptr);
        return 0;
}
usr@DESKTOP-xxxxx  /c/users/usr/Desktop
$ g++ main.cpp  -o app
main.cpp: In function 'int main()':
main.cpp:8:9: error: 'HSLC' was not declared in this scope
    8 |         HSLC ptr;
      |         ^~~~
main.cpp:9:17: error: 'ptr' was not declared in this scope
    9 |         SLOpen(&ptr);
      |                 ^~~
main.cpp:9:9: error: 'SLOpen' was not declared in this scope; did you mean '_lopen'?
    9 |         SLOpen(&ptr);
      |         ^~~~~~
      |         _lopen
usr@DESKTOP-xxxxx  /c/users/usr/Desktop

Are there any missing linking switches in the compile command?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
loaded_dypper
  • 262
  • 3
  • 12
  • What compiler exactly do you use? If it's gcc from msys2 or something, its headers may lack full support of Windows-specific stuff, including this one. I see similar errors with my msys2, but Visual Studio (not Visual Studio Code) works just fine. – yeputons Jul 15 '23 at 20:29
  • Are you sure you're building the correct file? That you really saved it before building? If you're doing the command `cat main.cpp` or `type main.cpp`, is it showing the file you expect? – Some programmer dude Jul 15 '23 at 20:32
  • @Someprogrammerdude yes i am sure of the file – loaded_dypper Jul 15 '23 at 20:33
  • @yeputons the compiler of choice is `mingw-w64` from msys2, isn't there a way to use the header file or do i have to change the compiler? – loaded_dypper Jul 15 '23 at 20:35
  • Please type the file anyway, just to make *really* sure. And since the file is so short, please copy-paste (as text!) the full command to type the file, its output, followed by the command to build and the errors. All as one single large code-formated text-block. – Some programmer dude Jul 15 '23 at 20:38
  • Re "linking switches"? Are these compiler errors? The linker doesn't know about C or C++ scope. It ssems unclear which of C or C++ you want to use anyway. – Weather Vane Jul 15 '23 at 20:40
  • 1
    @loaded_dypper You definitely need to install _something_, even "ucrt" version from msys2 does not include the correct header. Probably you need to install Windows SDK from Microsoft, but I'm not sure if gcc will play along, see some very old (and probably outdated) question [here](https://stackoverflow.com/q/2022112/767632). – yeputons Jul 15 '23 at 20:45
  • 1
    You could do it using dynamic linking with the help of `LoadLibrary` but that would be a bit harder – Weed Cookie Jul 15 '23 at 20:48
  • @WeatherVane I want to use cpp but if it works in `c++` then it should also work in `c` right ? – loaded_dypper Jul 15 '23 at 20:53
  • @Someprogrammerdude my bad forgot to add the header, but even with the header I still get the same error – loaded_dypper Jul 15 '23 at 20:55
  • I can [replicate](https://godbolt.org/z/aa4d8oT1e) the problem. [The `SLOpen` documentation](https://learn.microsoft.com/en-us/windows/win32/api/slpublic/nf-slpublic-slopen) only mentions the `slpublic.h` header file, which is found by the compiler (or you would get other errors). So I would argue that there's something missing from the documentation, more specifically another header file that needs to be included. – Some programmer dude Jul 15 '23 at 21:12
  • And [this overview of the `slpublic.h` header file](https://learn.microsoft.com/en-us/windows/win32/api/slpublic/) doesn't mention the type `HSLC` anywhere. – Some programmer dude Jul 15 '23 at 21:17
  • @Someprogrammerdude if use *CL* (*msvc*) all is compile ok – RbMm Jul 15 '23 at 21:32
  • 1
    `HSLC` should be defined near the top of `slpublic.h` as `typedef PVOID HSLC;`, if your copy of `slpublic.h` does not do that then you are using an outdated version and should update your Windows SDK. Otherwise, just define `HSLC` in your own code before using it. – Remy Lebeau Jul 15 '23 at 22:38
  • 2
    @Someprogrammerdude MinGW/msys2 provide their own headers, not ones from Windows SDK provided by Microsoft. They sometimes miss stuff. If anything, that's not a documentation issue. – yeputons Jul 16 '23 at 09:51

1 Answers1

1

This is what the errors you show are telling you:

$ g++ main.cpp  -o app
main.cpp: In function 'int main()':

first, there's no error about finding slpublic.h include file, so it is found somewhere in your system. It has been included correctly, but probably that file is not the one you need to include (see below)

main.cpp:8:9: error: 'HSLC' was not declared in this scope
    8 |         HSLC ptr;
      |         ^~~~

This error means that HSLC is nothing known to the compiler (probably it should be a type) Most probable reason for this is that you have not read the documentation and have for some reason mispelled that name. Or it can be that you have included the wrong .h file.

main.cpp:9:17: error: 'ptr' was not declared in this scope
    9 |         SLOpen(&ptr);
      |                 ^~~

Of course, if HSLC is not a valid type, the declaration for ptr has been ignored by the compiler, so this error will cancel too, when you correct the error above.

main.cpp:9:9: error: 'SLOpen' was not declared in this scope; did you mean '_lopen'?
    9 |         SLOpen(&ptr);
      |         ^~~~~~
      |         _lopen

This error also means that SLOpen is nothing known to the compiler. Are you sure that slpublic.h is the file you need to #include? The file has been correctly included in your program, but most probably it is not the correct one.

Luis Colorado
  • 10,974
  • 1
  • 16
  • 31