# Using windows types from a C++ class library

## Recommended Posts

Hi, I'm trying to create a C++ Windows Forms Application in Visual Studio 2008 that will eventually become a level editor. My hope is to wrap up my game-code (which exists in a separate project) into a class library, and use that DLL in both the level editor, and the game executable itself. I've read that I can pass an HWND from a WinForm component to my class library, and use that as a DirectX drawing surface. Sounds great, however I can't seem to get the definition for HWND without introducing a river of compiler errors complaining about IServiceProvider being an ambiguous symbol... I'm #including <windows.h> from within the class library to get the HWND definition. Is that the wrong way to do this? I admit, I don't know enough about DLL development to be sure I'm asking the right questions. Any help would be appreciated!

##### Share on other sites
For instance, here's the only .h in the class library:

// DXClassLibrary.h#pragma once#include <windows.h>using namespace System;namespace DXClassLibrary {	public ref class Class1	{		HRESULT InitDevice( HWND hWnd );	};}

This produces an error:
Error 1 error C2872: 'IServiceProvider' : ambiguous symbol C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\ocidl.h 6238

The "using namespace System;" was auto-generated by VS2008, and does seem to impact the situation. Moving it to before the #include results in 9 IServiceProvider errors instead of 1 when the code is left as stated above.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628277
• Total Posts
2981779

• 10
• 11
• 17
• 11
• 9