|
Hi all,
I am using an activex control which is registered under regsvr32. I created an MFC-dialog based aplication.I added activex control to the dialog box. And created a member-variable for the activex control thru class wizard.The member variable is m_myportcontroller.I called the activex method from a non-static member function of the dialog box using the member-variable as follows and worked fine.
ex:- void CSampleDlg::process(void)
{
m_myportcontroller.Close();
}
But i need to call the portcontroller methods from a static member function of a dialog based application (MFC).
ex:- static void CSampleDlg::process(void)
{
m_myporcontroller.Close(); // Not accessible because static function
}
Please send sample code of how to access the methods from static function. Very urgently needed.Early reply is appreciatable. Awaiting for the reply,
I had a problem in accessing Activex control methods from a static function
|
|
|
|
|
vanip wrote: But i need to call the portcontroller methods from a static member function of a dialog based application (MFC).
ex:- static void CSampleDlg::process(void)
{
m_myporcontroller.Close(); // Not accessible because static function
}
You have to create an instance of portcontroller inside the static method. That is how static methods work since they are not instance methods but class methods.
For eg:
static void CSampleDlg::process(void)
{
portcontroller pc;
pc.Close();
}
or
static void CSampleDlg::process(portcontroller& pc)
{
pc.Close();
}
vanip wrote: Please send sample code of how to access the methods from static function. Very urgently needed.
No.
Nibu thomas
Software Developer
|
|
|
|
|
Thanks nibu thomas,
I tried this way. But getting run time assertion error.
Any other way??
|
|
|
|
|
Static member functions do not have the this pointer. So they cannot access nonstatic class member data.
In your case m_myportcontroller is declared as a non static data member.
Vini
|
|
|
|
|
Why does the function have to be static? Some kind of callback?
A lot of callbacks takes a LPVOID parameter which can be used to provide the this-pointer and in the static member function type cast it so that it's possible to access non-static member variables and functions.
--
Roger
It's supposed to be hard, otherwise anybody could do it!
|
|
|
|
|
Thanks vinaya,
How to make that static?
I tried keeping static keyword in front of CPortController m_myportcontroller. But i am getting linker error. Do you know how to make that member as static??
|
|
|
|
|
Thanks Roger,
The function is to be static because, i am calling this process function in a thread. How to pass the LPVOID parameter to this process function??
|
|
|
|
|
Static member data need to be defined outside the class declaration. You can declare the CPortController member variable as static.
static CPortController m_myportcontroller ;
In the CSampleDlg cpp file, define the static variable as
CPortController CSampleDlg::m_myportcontroller;
Vini
|
|
|
|
|
The thread controlling function can be a non-static member of the class.
When you spawn the new thread with e.g. AfxbeginThread, you should pass the this-pointer as the LPVOID parameter. Your thread controlling function takes a LPVOID as argument which would now be your this-pointer. Type cast it and you'll be able to access both non-static member variables and functions from your thread.
Joe Newcomer has written a very nice article about threading that I strongly recommend everyone who is doing multithreading. You'll find it here[^]. He's got a lot of very useful tips, tricks and how-to's on his site.
When you're done with the threading stuff, a new problem may occur depending on how your ActiveX works. If you plan to use COM objects from a thread you have to initialize COM for that thread by a call to ::CoInitialize or similar. This sets up a new apartment. Now you have another problem: you can't cross apartment boundaries without marshalling the COM interface. Have a look at ::CoMarshalInterThreadInterfaceInStream and ::CoGetInterfaceAndReleaseStream for info about how to do that.
This is the correct way to do this. You have to marshal the interface. There are no shortcuts.
Post again if you have more troubles. If they are COM/ActiveX related, post your query in the COM forum.
Hope this helps
--
Roger
It's supposed to be hard, otherwise anybody could do it!
|
|
|
|
|
Thanks Vini,
i implemented , but getting comple errors. Can u specify in more detail???? please!!!
|
|
|
|
|
What are the compile errors you are getting? Specify the exact error messages, if possible.
Vini
|
|
|
|
|
We have a structure that we declare to be __declspec(allocate)'d into a particular section that we, earlier, declare with #pragma section(). This structure is never referred to by name, it is accessed by traversing the section itself.
When this structure was in our main program it was accessible. Now that I have moved it out into another library it is not. It appears that the linker has dead-stripped the symbol because it has determined that it's never getting used. I would like to be able to tell the linker to actually keep it.
Is there a keyword / link option I can use to do this?
|
|
|
|
|
hi,
Can i customize the ListCtrl Tabs & Move them when a costomize scrollbar Moves.
vinod c s
Integral Softech
|
|
|
|
|
vinivc wrote: Can i customize the ListCtrl Tabs & Move them when a costomize scrollbar Moves.
Well I didn't get you. What do you mean by ListCtrl tabs. Can you be more specific.
Nibu thomas
Software Developer
|
|
|
|
|
Hi vinivc ,
What's Tabs in the CListCtrl
|
|
|
|
|
hi,
Thanks for showing intrest in solving the problem.
I mean the ListLctrl Column header(i.e the Tabs which represent the column Header ).
I want to Customize them & use a customised HScroll & Vscroll to move the
contents of ListCtrl.
"(CListCtrl class in MFC)"
|
|
|
|
|
vinivc wrote: I want to Customize them & use a customised HScroll & Vscroll to move thecontents of ListCtrl.
They are known as HeaderCtrl and MFC equivelent class is CHeaderCtrl
vinivc wrote: I want to Customize them & use a customised HScroll & Vscroll to move thecontents of ListCtrl.
get the Pointer of listCtrl Header ctrl pointer using CListCtrl::GetHeaderCtrl( ); function
|
|
|
|
|
|
I've got an old C code header I'm porting to VC++ 2005. The code implementation looks something like:
#include <mmsystem.h>
...
void Initech::MyFunction()
{
midiInAddBuffer(...);
}
Compiling this, I get the following error:
error LNK2028: unresolved token (0A000016) "extern "C" unsigned int __stdcall midiInAddBuffer(struct HMIDIIN__ *,struct midihdr_tag *,unsigned int)" (?midiInAddBuffer@@$$J212YGIPAUHMIDIIN__@@PAUmidihdr_tag@@I@Z) referenced in function "void Initech::MyFunction()" (?MyFunction@@$$FYAIPAUmidihdr_tag@@@Z) Midi.obj
With C++ not being my native tongue, I'm kind of stumped at this error; what do I need to do to resolve it? Any help would be appreciated.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
you need to include winmm.lib into your build
|
|
|
|
|
|
try
#pragma comment(lib,_T("winmm.lib")) at the top of your cpp file where you calling Window multimedia related function
|
|
|
|
|
Thanks, I'll give that a try.
|
|
|
|
|
I've inherited an old vc++ 6 project, and loaded it into 2005.
Cleaning up the project, I tried removing a file called resource.hm, which contained the following line:
<br />
#define HIDC_TEST_LIST 0x80d43575 // IDD_TEST_DIALOG [Neutral]<br />
The IDD_TEST_DIALOG dialog does not exist in the project, nor are any of the resources defined as Neutral.
I also removed the following lines from the .rc file:
<br />
#define APSTUDIO_HIDDEN_SYMBOLS<br />
#include "resource.hm"<br />
#undef APSTUDIO_HIDDEN_SYMBOLS<br />
When I build, the lines are auto-generated in the resource script, and an empty resource.hm is created, causing a compile error.
From MSDN:
Your project's resource.hm file will only be created by the development environment when one or more dialog boxes have controls and when those controls have HelpID properties set to True in the Properties Window.
I scanned the .rc script for any references of HIDC_TEST_LIST, and none were found. I scanned for other HelpIDs, nothing. How in the heck do I get rid of this thing?
Montreal great Guy Lafleur, quoted by CBC on being mugged while vacationing recently in Buenos Aires: "I didn't have any time to react before I got a sucker-punch in the eye. It was like one of the players from the Bruins."
|
|
|
|
|
Delete and re-create the resource file, at least thats how I get it to work when loading problematic files into VC6.
|
|
|
|