|
For an item of hardware I have written a Shared library to make it easy to use the API for this hardware. The library sets up data structures and handles, buffers etc for simple program use.
For example to arrange data to be transmitted I call routines like:-
UINT16 TransmitData( UINT unit, UINT addr, TXBUFFER * tx_buffer );
However in VS2008 I used C++ in a MFC dialog application, which all worked well.
Having moved to VS2010, I now see that the intellisence does not work with this product for C++.
So my thoughts were to use C# for the Windows forms and link in the Shared Library.
My question is do I need to general a DLL rather than a Shared Library so that I can use C++, C# and perhaps VB. Is this correct and what are the procedures to follow.
The libray is built using C. I include the API.lib and API.h along with the DLL that came with the API s/w environment.
Many thanks,
Andy
|
|
|
|
|
|
Hi,
I'm trying to create a deskband (windows xp). The class which implement
IDeskBand is CBand. I've created some brush in
the constructor of this class. And destroyed in destructor.
right click taskbar->toolbars-> select MyBand, now my deskband is visible.
then right click taskbar->toolbars->MyBand, now my deskband is gone.
But the gdi items are still in memory ? It seems
the destructor is not called.
If repeat show, hide deskband, the gdi object count increases with every time.
I've created it as specified in the following url.
http://msdn.microsoft.com/en-us/library/cc144099(v=vs.85).aspx
CBand::CBand()
{
MessageBox(0, "Construct", 0,0) ;
m_lRef = 1 ;
}
CBand::~CBand()
{
MessageBox(0, "Destruct", 0,0) ;
}
DWORD __stdcall CBand::AddRef()
{
return InterlockedIncrement(&m_lRef) ;
}
DWORD __stdcall CBand::Release()
{
if( InterlockedDecrement(&m_lRef) == 0 )
{
delete this ;
}
return m_lRef ;
}
HRESULT __stdcall CBand::QueryInterface( REFIID riid , void** ppvObj )
{
*ppvObj = NULL;
if(IsEqualIID(riid, IID_IUnknown))
{
*ppvObj = this;
}
.
.
.
.
if(*ppvObj)
{
(*(LPUNKNOWN*)ppvObj)->AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
HRESULT __stdcall ShellFactory::CreateInstance(IUnknown* pUnknownOuter , const IID& iid , void** ppv )
{
if( pUnknownOuter != NULL )
{
return ResultFromScode( CLASS_E_NOAGGREGATION ) ;
}
if( IsEqualCLSID(m_clsid , CLSID_MyBand))
{
CBand * pObj = new CBand() ;
if( pObj == NULL )
{
return E_OUTOFMEMORY;
}
HRESULT hRes = pObj->QueryInterface( iid , ppv ) ;
if(FAILED(hRes) )
{
pObj->Release() ;
}
return hRes;
}
return S_FALSE ;
}
Thanks & Regards
|
|
|
|
|
I am trying to call a function in one class from another class and when I do,
I can not get or set data that is in any of the Edit Controls in my dialog
of the function that I am calling.
I have multiple columns of simuliar controls that I want to copy from one to the others.
So I call my copy function and try to copy from one column to the selected others. Slider Controls,
Check boxes, and Radio Buttons seem to work fine, but I can not get the Edit contols to work.
Here is an example of the code I have:
class Dialog1 : public CDialog
{
public:
void CallCopyFnc();
private:
Dialog2* myDlg2;
}
class Dialog2 : public CDialog
{
public:
void CopyDataFnc();
}
Dialog1::OnInitData()
{
myDlg2 = new Dialog2;
}
Dialog1::CalllCopyFnc()
{
myDlg2->CopyDataFnc();
}
Dialog2::CopyDataFnc()
{
CString str;
str.Format("0x%08X", number);
EditCtrl.SetDlgItemTextA(idEditCtrl, str);
}
Any help would be appreciated as to what I am doing wrong. Thanks in advance!
David
modified on Tuesday, April 19, 2011 12:33 PM
|
|
|
|
|
Member 7814600 wrote:
Because the edit control does not exist until Dialog2::OnInitDialog() .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
All the dialogs and controls should have been initialized before when the program starts up. I just want to be able to access those same controls and be able to get/set the data from them. How is the best way to go about this?? If I add a button to the dialog that has the columns that I want to copy and call my function when the button is pressed - all the code seems to work OK. This would mean that I could put this button and code in each dialog and it would work - but I wanted to have a single point in a popup window that called the copy function for each dialog based on the active dialog. That is why I was trying call call the function from another class. Any help on how I can do this properly would be appreciated.
David
|
|
|
|
|
Your code does not show any controls (like CEdit) in the dialog header files. Do you create them dynamically? Where?
|
|
|
|
|
They were created with the toolbox and added into the dialog.
They look like this in Dialog2:
CEdit myEditCtrl[6];
in the properties, it is named idEditCtrl1-6.
|
|
|
|
|
jhoesche wrote: All the dialogs and controls should have been initialized before when the program starts up.
Why would you think/assume that? Controls on a dialog do not get created until the parent/dialog gets created (i.e., OnInitDialog() ).
jhoesche wrote: I just want to be able to access those same controls...
You should only do this from within the dialog itself.
jhoesche wrote: If I add a button to the dialog that has the columns...
A button having columns?
jhoesche wrote: This would mean that I could put this button and code in each dialog and it would work - but I wanted to have a single point in a popup window that called the copy function for each dialog based on the active dialog. That is why I was trying call call the function from another class. Any help on how I can do this properly would be ppreciated.
Do you have a class derived from CDialog that acts as the base class? If so, you could create a virtual function in that class that each derived class could implement. When called, the internals of that function would simply enumerate all child controls and populate an array of some sort (supplied by the parent) with their values.
[edit]
I just realized that this, if used with a modal dialog, will not work as I initially thought. It's possible that I do not fully understand your requirements, thus you'll need to scrap my suggestion.
[/edit]
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
modified on Wednesday, April 20, 2011 4:37 PM
|
|
|
|
|
I am new to VC++ and I am not sure if I am asking the corect question. There is not a base class besides CDialog - all the dialogs were created from Add Resource in the Resource View tab.
DavidCrow wrote: If so, you could create a virtual function in that class that each derived class
could implement.
I am not sure that I know how to do this. Do I need to have the base class be the main dialog (Dialog1) and then derive all the other dialogs from the base?
DavidCrow wrote: A button having columns?
Not a button having columns - but a dialog that has rows and columns of Edit Controls where a each column is a group of controls. I need to copy from one column to the others to enable setting the value easily.
|
|
|
|
|
Use ClassWizard (Ctrl+W) to derive a class from CDialog . Then add the following to it:
class CBaseDialog : public CDialog
{
public:
virtual int ReadControls( CArray *pArray ) {}
};
Now in your other dialogs, derive them from CBaseDialog instead of CDialog . You'll have at least one change in the .H file and several in the .CPP file.
The virtual method means that the derived classes can choose to implement their own version of it or not. In your implementation of it, you'd likely want to enumerate each of the dialog's child controls, and put their values in the array parameter. Check out EnumChildWindows() .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
I am not sure that I understand - if I call the function from the base class - how does it get down to the derived classes? I thought that it worked the other way around - from the derived classes up? What I was originally trying to do was to call a function in one class from another and be able to use all the controls on the dialog of the called function. What is the best way to do that?
|
|
|
|
|
jhoesche wrote: I am not sure that I understand - if I call the function from the base class...
You don't. It gets called from the owner of the derived dialogs (e.g., the application).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
DavidCrow wrote: You don't. It gets called from the owner of the derived dialogs (e.g., the
application).
I do not understand - can you give me an example of how this will work. Can I contact you directly by email if I need to?
|
|
|
|
|
jhoesche wrote: Can I contact you directly by email if I need to?
That would defeat the purpose of others being able to help you.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
My requirement is in MFC vc6.0 application
I need a function which receives a string and a float value
The string that i pass is a variable name used in the application.
When the function is called the passed value should get assigned to the variable which is passed as a string
Function SetVal(CString VarName, float value)
{
Suppose <varname> is Esim->Aut[35] and <value> is 5.5665
This function should set Esim->Aut[35] to 5.5665
}
Anybody pl help if this is possible.
|
|
|
|
|
C++ does not have a built-in way to associate a variable name with a string, at runtime. so, you will need to construct a way to create this association explicitly.
there are many ways to do it. the most basic is something like this:
void SetVal(CString VarName, float value)
{
if (VarName=="Var1")
Var1 = value;
else if (VarName=="Var2")
Var2 = value;
else if (VarName=="Variable3")
Variable3 = value;
etc..
}
|
|
|
|
|
Thanks for your help.
But... This doesnt help me
Becoz I have more than 1000 variables in my application for which I have to write this code to check for the variable.
Pl. suggest me if there is any direct way of doing the mapping.
|
|
|
|
|
manoharbalu wrote: Pl. suggest me if there is any direct way of doing the mapping.
there is no direct way of doing this. C++ does not know the 'name' of your variables at runtime.
if you have a lot of variables to deal with, you can use a std::map to map strings to floats. you will have to add the variable names to the map explicitly, but accessing the stored values will be simpler.
Google "C++ variable name map". this is a common question, and there are a lot of solutions out there.
|
|
|
|
|
manoharbalu wrote: Becoz I have more than 1000 variables in my application for which I have to write this code Write yourself a little app that will output the variable names like this:
"variable-name", variable-name,
Do that for all the variables, paste the output into your program, and you have a table that you can search at run-time.
By the way, use of sms-speak (Becoz, pl.) is not appreciated on this site.
|
|
|
|
|
I don't know of such a way but if you elaborate on your requirement someone here might help you on this. Another way would be to keep a check on the string passed and then compare it with what you want, thereafter set the value in the required value but then this may be an additional overhead depending on the parameters used in your code.
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
manoharbalu wrote: This function should set Esim->Aut[35] to 5.5665
So why not just use:
Esim->Aut[35] = 5.5665;
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
Have you considered using some kind of macro (using a #define ) instead of a function call?
|
|
|
|
|
Hi,
I tried to minimize the application using below code:
HWND lHwnd = FindWindow("Shell_TrayWnd",NULL);
SendMessage(lHwnd,WM_COMMAND,MIN_ALL,0);
I am confused with, Will it work with other language OS because I used hard code "Shell_TrayWnd"?
|
|
|
|
|
What do you mean by "other language OS"? Unix? Mac? Or do you mean other language, like C#?
|
|
|
|