Solved

ATL and Casting Controls

Posted on 2008-06-26
5
389 Views
Last Modified: 2013-12-14
I need some help on working with controls in an visual c ATL project.

I have some basic examples that show how to Interact with controls using:
SetDlgItemText
CheckDlgButton
SendDlgItemMessage

However, now i have a more advanced control type, spin control and I need more control.

I want to be able to map a message for this control to a function and then cast it this:

CSpinButtonCtrl* hWnd = (CSpinButtonCtrl*)lParam;

So i can follow the many examples provided about SpingButtonCtrl.

Howerver, I get the following error:

error C2065: 'CSpinButtonCtrl' : undeclared identifier


Any Suggestions?

Thanks,

Jason
0
Comment
Question by:cristo1701
  • 3
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 250 total points
Comment Utility
CSpinButtonCtrl http://msdn.microsoft.com/en-us/library/sfac27cz(VS.80).aspx is declared in the header file afxcmn.h I am not certain if this will work in an ATL project but try including it:

#include <afxcmn.h>
0
 

Author Comment

by:cristo1701
Comment Utility
LordOfPorts:

I already tracked it down and tried to include that file.

However, I got the following error:

C1189: #error :  Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]

So then I #define _AFXDLL
And Got this error:
WINDOWS.H already included.  MFC apps must not #include <windows.h>

Did some research and found that i need to add these lines before #include <atlbase.h> in StdAfx.h
only to get stuck again with the following error:
fatal error LNK1169: one or more multiply defined symbols found

Thanks,

Jason
0
 

Author Comment

by:cristo1701
Comment Utility
Alright,

I figured it out finally, I found out this project is actually a MFC dll created by Windows Media Player Wizard.

They use there own version of DllMain, which came into conflict when I included #include <afxcmn.h>

I did all the above and had to replace
extern "C"
with
extern "C" { int _afxForceUSRDLL; }

to force use of my DllMain not the one in the MFC library

this useful tip is expalined here:
http://www.codediscuss.com/mfc/dllmain-in-mfc-dll/

I'm totally new to windows programming and DLLs, does this look right? It seems to work.
0
 
LVL 19

Expert Comment

by:LordOfPorts
Comment Utility
I am not certain if it will have any impact on any other functionality however if you have tested it successfully and it is working properly give it a try. Alternatively you can also try to access Project -> Properties and under "Use of MFC" select "Use MFC in a Shared DLL" to see if it makes a difference.
MFCSharedDLL.png
0
 

Author Comment

by:cristo1701
Comment Utility
I tried that before and it didn't seem to have any affect on my issue.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now