Encapsulating third party api

I was wondering how I could put some abstraction between winapi and winsock and my code. I want to make a tcp socket class, but I keep ending up with private variables that have winapi types. I have looked at type erasure and making fields void*, but the type I am using is created using a function that returns a non-pointer type.

SOCKET sock;
sock = socket(...);

How would I keep a private version of sock in my class? I have tried forward declaring, but it leads to issues because winapi uses a bunch of typdefs.

Edit: I guess I wasn't clear based on the results I'm getting from other people. I want to keep the variables from winapi out of my header file.
Last edited on
Creating a wrapper class in a new header solved the problem.

1
2
3
4
5
6
#include <windows.h>
class WinSockWrapper
{
    public:
        SOCKET socket;
};


And then in the header for the other file I did:
1
2
3
4
5
6
7
class WinSockWrapper;
class MyClass
{
    ...

    WinSockWrapper *winSocket;
}


And then in the definitions for MyClass any time I needed to use the actual SOCKET instance I did:
1
2
3
4
5
6
#include "winsockwrapper.h"

...

winSocket->socket = socket(...);
connect(winSocket->socket,...);
Topic archived. No new replies allowed.