Chryso

Hello,

So I installed the platform SDK, got it running with VC++ EE. Now i want to do some UPnP control. So I am looking at how to do it. And I am limiting myself for now to copy / pasting Microsoft code that is found in the help. Though am having a hard time with it Smile

If anyone has a library that takes in entry 1 IPaddress, 1 int and as an output 1 int (int represents port number) and creates a forwarding on the nat router found on the network, it would be great Smile Passing a port number is great to say which port you want forwarded but if it is already forwarded might as well have the new port as an out parameter Smile

So going back to the code I copy / pasted:

Here are the first 2 errors I have:

1>UPNPX86Lib.obj : error LNK2028: unresolved token (0A000021) "extern "C" long __stdcall CoCreateInstance(struct _GUID const &,struct IUnknown *,unsigned long,struct _GUID const &,void * *)" ( CoCreateInstance@@$$J220YGJABU_GUID@@PAUIUnknown@@K0PAPAX@Z) referenced in function "long __cdecl FindUPnPDevice(wchar_t *)" ( FindUPnPDevice@@$$FYAJPA_W@Z)
1>UPNPX86Lib.obj : error LNK2028: unresolved token (0A000024) "extern "C" void __stdcall SysFreeString(wchar_t *)" ( SysFreeString@@$$J14YGXPA_W@Z) referenced in function "public: virtual long __stdcall CUPnPDeviceFinderCallback:Big SmileeviceAdded(long,struct IUPnPDevice *)" ( DeviceAdded@CUPnPDeviceFinderCallback@@$$FUAGJJPAUIUPnPDevice@@@Z)

How do I solve these

Regards,
Chryso


Re: Visual C++ General Errors when using UPnP.h

Simple Samples

Copy the error messages and paste into a work area and then delete exraneous portions as necessary. Then you can have something such as:

extern "C" long __stdcall CoCreateInstance(struct _GUID const &,struct IUnknown *,unsigned long,struct _GUID const &,void * *)
extern "C" void __stdcall SysFreeString(wchar_t *)

So the linker cannot find CoCreateInstance and SysFreeString, which are in the Windows SDK. So look at the documentation of them; at the bottom is something such as:

Requirements

For an explanation of the requirement values, see Requirements (COM).

Windows NT/2000/XP: Requires Windows NT 3.1 or later.

Windows 95/98: Requires Windows 95 or later.

Header: Declared in objbase.h.

Library: Use ole32.lib.

I think normally the necessary libraries are automatically used for linking so you probably created the project in a manner that did not get the defaults, or you changed something tht caused the problem. The problem might be related to the express edition and if so then you will likely get better help in the forum for it.






Re: Visual C++ General Errors when using UPnP.h

Chryso

Well,
I installed platform SDK after I created the project.
Thank you for the information, I ll try to see what happens when I recreate the project

Edit: did not change anything

The weird thing is, that those function, visual c++ ee finds them ...

Going to ask the dumb question, but how do I add the missing stuff to my application

I tried: #pragma comment(lib, "ole32.lib")

Tried the /CLR option too, did not change a thing

regards,
Chryso




Re: Visual C++ General Errors when using UPnP.h

Chryso

So, my project was a CLR console application
If I use a win32 console application I have the following error:

error LNK2019: unresolved external symbol __imp__CoCreateInstance@20 referenced in function _wmain

which is still a linking error

here is the code though:

Code Snippet


// UPNPX86LibUnmanaged.cpp : Defines the entry point for the console application.

#pragma comment(lib, "ole32.lib")
#include <objbase.h>
#include "stdafx.h"
#include <upnp.h>

int _tmain(int argc, _TCHAR* argv[])
{
printf("Hello World");

HRESULT hr = S_OK;
IUPnPDeviceFinder *pDeviceFinder = NULL;


hr = CoCreateInstance(CLSID_UPnPDeviceFinder,NULL,1,IID_IUPnPDeviceFinder, (void **) &pDeviceFinder);

return 0;
}


regards,
Chryso




Re: Visual C++ General Errors when using UPnP.h

Simple Samples

I am sorry, I probably misled you. That COM stuff is complicated in ways that it does not need to be. I was confused but I do not know what the solution is. Since it is not within the scope of the MSDN VC forums, you are likely to get better help in a forum in which your question is within the scope of the forum.

If you can find sample programs, then get as much from those resources as possible. Really, really use them. I am currently attempting to use the HTML DOM, which is also implemented for Windows as COM objects and it is very frustrating getting anything with that. You will be lucky to get someone to help you with COM such as this, and I say that only from past experience of not getting anything.






Re: Visual C++ General Errors when using UPnP.h

Viorel.

Chryso wrote:

[...]

Code Snippet


// UPNPX86LibUnmanaged.cpp : Defines the entry point for the console application.

#pragma comment(lib, "ole32.lib")
#include < objbase.h >
#include "stdafx.h"
#include < upnp.h >

[...]


I think you should reorganize the beginning of your file:

Code Snippet

#include "stdafx.h"

#include <objbase.h>

#include <upnp.h>

#pragma comment(lib, "ole32.lib")

. . .

I hope this helps. (The stdafx.h file has a special role and has to be the first #include directive).





Re: Visual C++ General Errors when using UPnP.h

Chryso

Hello,

That worked, thanks a lot.

Regards,
Chryso