Hi all,
I am trying to build a simple application that consist of a function that disable and enable connection.I am using Qtcreator to code.with mingw.I've found some online code which I've used for understanding and to test if it works in Qt:
Code:
#include <windows.h>
#include <iphlpapi.h>
#include <objbase.h>
#include <netcon.h>
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
...
...
bool EnableConnection(LPCWSTR wszName, bool bEnable)
{
bool result = false;
typedef void (__stdcall * LPNcFreeNetconProperties)(NETCON_PROPERTIES* pProps);
HMODULE hmod = LoadLibraryA("netshell.dll");
if (!hmod)
return false;
LPNcFreeNetconProperties NcFreeNetconProperties = (LPNcFreeNetconProperties)GetProcAddress(hmod, "NcFreeNetconProperties");
if (!NcFreeNetconProperties )
return false;
INetConnectionManager * pMan = 0;
HRESULT hres = CoCreateInstance(CLSID_ConnectionManager,
0,
CLSCTX_ALL,
__uuidof(INetConnectionManager),
(void**)&pMan);
if (SUCCEEDED(hres))
{
IEnumNetConnection * pEnum = 0;
hres = pMan->EnumConnections(NCME_DEFAULT, &pEnum);
if (SUCCEEDED(hres))
{
INetConnection * pCon = 0;
ULONG count;
bool done = false;
while (pEnum->Next(1, &pCon, &count) == S_OK && !done)
{
NETCON_PROPERTIES * pProps = 0;
hres = pCon->GetProperties(&pProps);
if (SUCCEEDED(hres))
{
if (wcscmp(pProps->pszwName,wszName) == 0)
{
if (bEnable)
result = (pCon->Connect() == S_OK);
else
result = (pCon->Disconnect() == S_OK);
done = true;
}
NcFreeNetconProperties(pProps);
}
pCon->Release();
}
pEnum->Release();
}
pMan->Release();
}
FreeLibrary(hmod);
return result;
}
fyi,
I have tried to link them up with these:
Code:
win32:LIBS += -Lc:/Path/Lib -liphlpapi -lole32 -lnetshell
win32:INCLUDEPATH += c:/Path/Include
My Lib folder contains:
libiphlpapi.a
libole32.a
netshell.dll
My Include folder contains:
netcon.h (found this file online)
However when i tried to build my application i get errors like:
1. undefined reference to CLSID_ConnectionManager or IID_INetConnectionManager and
2. __uuidof not declared.
3. and I think there is something wrong with the statement for __stdcall
Is there anything I've missed here???
I am new to programming in windows and have been unable to find any solution for this.Have encountered several errors like this already...How can I include all the dependent files and libs once and for all?I am unable to use visual studio although I have Visual C++ 08 installed because it is a requirement for me to use Qt in this project.
Will appreciate any valuable advice.
Thanks in advanced.