|
I am facing a critical problem when i place my control in ActiveX Cotainer.The problem is that the first time the control loads , it only shows the area in the rectangle (Previously in which Ellipse is drawn by default ) . Please help me out as to how to initialize the size of that rectangle in which the control is displayed ...
|
|
|
|
|
Hi,
I want to create run-time array for example I want to set the number
of elements in run-Time:
/**********************/
If i=0 then
CClass cls[j];
else
CClass cls[b];
/************************/
Best Wishes,
Thanks.
|
|
|
|
|
you will not be allowed to do this by the compiler. you'll have to allocate the memory for your array dynamically, on the heap :
CClass cls* = new CClass[j];
be sure that j is well defined, and non-negative !
another thing :
If i=0 Then must be traduced in C/C++ by
if (i == 0) { that means, be careful of the ( ) between the condition statement, and == for the equal operator (= is the affectation operator).
cheers,
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Heres your solution
CClass* cls;
if (i==0)
cls = new CClass[j];
else
cls = new CClass[b];
Rahim Rattani
Software Engineer,
Matrix Systems (Pvt) Ltd.,
Karachi - Pakistan
|
|
|
|
|
And to complement the previous responses, don't forget to free the memory after having used it:
if (cls)<br />
{<br />
delete[] cls;<br />
cls = NULL;<br />
}
|
|
|
|
|
yes, of course !
and to be more better, you can encapsulate this code into the destructor ~CClass() ...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hi all,
I have a problem. I need to start a long computing work when the user clicks a dialog button. During this time the button needs to be disabled. The following simple code doesn't work. Despite the fact that the button changes state from enable to disabled (grayed), it actually gets the mouse inputs. Some of you knows the reason? I wasn't able to disable this button and then I had to write a workaround.
Thanks,
Daniele Godi
///////////////////////////////////////////////////////////////
Sample code
void CMyDlg::OnBnClickedButton1()
{
// disable the button
m_ctrlButton1.EnableWindow(FALSE);
BeginWaitCursor();
DoSomeLongWork();
EndWaitCursor();
// workaround, I have to remove manually the mouse input from
// the message queue
if (::GetInputState())
{
MSG msg;
while ( ::PeekMessage( &msg, NULL, NULL, NULL, PM_NOREMOVE ) )
{
// found a mouse message, remove it
if ((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST))
{
::PeekMessage( &msg, NULL, NULL, NULL, PM_REMOVE);
}
else
{
if ( !::AfxGetThread()->PumpMessage() )
{
// if FALSE exit both dialog and application
EndDialog(FALSE);
::PostQuitMessage( -1 );
return;
}
}
}
}
m_ctrlButton1.EnableWindow(TRUE);
return;
}
Daniele Godi
|
|
|
|
|
if you apply the EnableWindow() directly to a member object, you have to call UpdateData(FALSE) to update your controls with the changes done on the associated member object (and UpdateData(TRUE) for the opposite)...
otherwise, this single line also works :
((CButton*)GetDlgItem(IDC_MY_BUTTON))->EnableWindow(FALSE); I assume (of course) that IDC_MY_BUTTON is the ident of the button you want to change the state...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I'm sorry, it desn't work.
Ciao...
Daniele
|
|
|
|
|
|
The code is exactly the same I have provided on my first query. (Except for the workaround)
I work with MS Visual Studio .NET 2003
The application is MFC based.
The Dlg-box is modal
Build a empty application and add an handler to the OK button on the about box, then
1 - at the beginnig of the handling function disable the button that the user pressed using the wrapper class m_ctrlButtonOK.EnableWindow(FALSE) (same as GetDlgItem(ID)->EnableWindow(FALSE))
2 - perform a long work
::MessageBeep(MB_OK);
::Sleep(10000);
works fine...
3 - at the end of the function call m_ctrlButtonOK.EnableWindow(TRUE)
If you click on the OK button while it is disabled, you will see that after the work the handler function get called once again.
Thank you and ciao...
Daniele
|
|
|
|
|
Dear all, I found the solution and I like to share it with you.
I took the idea from an article I have found on your site,
http://www.codeproject.com/cpp/cppforumfaq.asp#ui_workerthread
I implemented this code within the button handler and... wonder!, it works.
OnButtonClicked()
{
m_crtlButton->Enable(FALSE);
while (Do_A_Bit_Of_Work())
{
MSG msk;
while(PeekMessage(&msg, NULL, NULL, PM_NOREMOVE)
{
AfxGetApp()->PumpMessage();
}
}
m_crtlButton->Enable(TRUE);
return;
}
Ciao and thanks for your kind help.
Daniele
|
|
|
|
|
Hi,
why don't u check LockWindowUpdate() and unLockWindowUpdate().
Lokesh
|
|
|
|
|
I'm sorry, it desn't work.
Ciao...
Daniele
|
|
|
|
|
Hi, All
I want to implement a signature mechanism. My application can
verify the validity of DLL for preventing others replace my dll.
This is just like CSP signature mechanism.
Thank you in advance for your help.
Owen.
|
|
|
|
|
Hi,
You can verify for the dll using its signatures stored in its headers. eg u can use TimeDateStamp of ur dll, or size of code base.. or u can set MinorImageVersion of the DLL when u build the data and verify the same...
u can check for size of headers sections so on...
better refer this article before u continue....
ms-help://MS.MSDNQTR.2004JAN.1033/dndebug/html/msdn_peeringpe.htm in MSDN
all the best...
gP_t_gr8
|
|
|
|
|
Hi,
I try to get the inserted row's ID (primary key) which was inserted to a table.
I tried the following API calls immediately after insert. I use the same m_hStmn for the insert and the select query.
This call is successfull however when I query the returned value using the SQLFetch and SQLGetData the returned SQLINTEGER is always zero!?
SQLExecDirect(m_hStmn, (SQLTCHAR*)_T("SELECT @@IDENTITY AS 'Ident'"), SQL_NTS)
I tried to use the more save SCOPE_IDENTITY() function, however these API calls fail.
The driver returns (for Access table) undefined function.
SQLExecDirect(m_hStmn, (SQLTCHAR*)_T("SELECT SCOPE_IDENTITY()"), SQL_NTS)<br />
SQLExecDirect(m_hStmn, (SQLTCHAR*)_T("SELECT SCOPE_IDENTITY() As [Ident]"), SQL_NTS)
In this case I got from the driver one parameter missing error code:
SQLExecDirect(m_hStmn, (SQLTCHAR*)_T("SELECT SCOPE_IDENTITY"), SQL_NTS)
Can anybody explain how can I correctly get the inserted row's ID? Why the above calls
fail ?
Thanks,
Abyss
|
|
|
|
|
How do you export a member function / class from and exe so that is can be called from a dll?
|
|
|
|
|
I've never had the need to export from an EXE, only from a DLL. Are you sure this is something you need/want?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
David,
I don't see away around it for what I am trying to accomplish.
Let me explain what I am trying to do and maybe it will make for sense.
My main application is just a framework that most useful functionality will be added thru plugins.
Each screen is described in XML and all communication is done by messages.
So, here is a simple example. The main application has a screen file that says it has two buttons on it. First a theme selector button which will call the theme.dll and exit button which sends a command to close the applcation. The Theme selector button will load the Theme selector dll which loads its own screen file which has the following information.
1) Theme name
2) Theme version
3) Theme author
4) List of screenshots
5) Next Button
6) Prev Button
7) Apply Button
Since the main application has no prior knowledge of this information the plugin must be responsible to maintaining and updating this data to the main application.
That is why I need my message function to be able to send data both directions.
bool OnMessage( CSystem *pSys, CMessage * pMsg );
The main application knows that the plugin registered the following controls:
1) 2 text controls
2) screenshot control
3) 3 buttons
In the main application the user presses the Theme Selector button. The theme plugin is loaded.
On the plugins screen the next button is pushed which sends a simple message to the plugin "theme.next"
OnMessage( CSystem *pSys, CMessage *pMsg )
{
if( pMsg->GetSubject() == "theme.next")
{
mainapplication->OnMessage( ... )
}
}
Hope that makes sense.
|
|
|
|
|
In your exe source:
#ifdef EXE_EXPORTS
#define EXE_API __declspec(dllexport)
#else
#define EXE_API __declspec(dllimport)
#endif
EXE_API bool OnMessage( CSystem *pSys, CMessage *pMsg )
{
...
return(true);
}
Define EXE_EXPORTS in the project settings when building the .exe.
This will export the function in the exe and create a .lib for the .exe when you build it.
For each plugin dll you need to include a header that defines the exported function(s) e.g. OnMessage(), and link the dll with the .exe's .lib file.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Okay,
But, can you get the name of function dynamically without including the .lib like you would get the address of a function in a dll.
Oh, does it matter if this function is a member function? Would you export it the same way?
Thanks,
Steve
|
|
|
|
|
smesser wrote:
But, can you get the name of function dynamically without including the .lib like you would get the address of a function in a dll.
You can use LoadLibrary() on an exe with exported functions; however first read all the MSDN remarks for LoadLibrary().
If you exported a c++ function or a class method you have to use the mangled name in GetProcAddress().
I am guessing that it would work. LoadLibrary() would see that the specified module (the exe) is already loaded into the process and not try and call DllMain() in it. Just remember to call FreeLibrary() as well to decrease the reference count for the module (exe).
smesser wrote:
Oh, does it matter if this function is a member function? Would you export it the same way?
You would export it as you would a member function from a dll.
That is, either export the entire class:
class EXE_API MyClass {
...
);
or just the method:
class MyClass {
...
EXE_API bool MyMethod( ... );
...
);
...cmk
Save the whales - collect the whole set
|
|
|
|
|
As David mentioned the more usual way is that the exe just calls known interfaces in the dll.
For you i would suggest a similar approach.
When the exe loads the dll have it call an Init() function that passes a pointer (or reference) for the App object to the dll, then the dll can just use that pointer (or reference) to call back to the exe. You don't need to use LoadLibrary() on the exe from the dll.
I get the impression that you want this as generic as possible, but at some point you have to tell each side how to talk to the other.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
cmk wrote:
When the exe loads the dll have it call an Init() function that passes a pointer (or reference) for the App object to the dll, then the dll can just use that pointer (or reference) to call back to the exe. You don't need to use LoadLibrary() on the exe from the dll.
I tried something like that and I couldn't get it to compile. I tried the following:
HWND hCore;
hCore = AfxGetApp()->m_pMainWnd->GetSafeHwnd();
CDialog* pDlg = DYNAMIC_DOWNCAST(CDialog, CWnd::FromHandlePermanent(hCore));
if (pDlg != NULL)
{
CCOREDlg *pCore1;
pCore1 = (CCOREDlg*)pDlg->GetRuntimeClass();
CSystem * pSys = NULL;
IMessage *pMsg = NULL;
g_pSystem->pCore = pCore1;
g_pSystem->pCore->OnMessage( pSys, pMsg );
}
This code works fine from the exe but externally it complains that CCOREDlg is unknown.
Maybe I was doing something wrong??
cmk wrote:
I get the impression that you want this as generic as possible, but at some point you have to tell each side how to talk to the other.
Well, that is the crux of my dilemma. Communication to the dll is simple but the other direction is some what of a buggard.
Best case scenario for me would be to export the OnMessage function from the exe and then import it in the dll. But, I am a little fuzzy on the details for doing this.
Thanks for all the input.
|
|
|
|