|
i want to test how to change icon of an exe file with an icon file by function Updateresource() - do you know where i can find sample of this kind?
thx
includeh10
|
|
|
|
|
This question is to general. It sounds like you are talking about changing an existing exe. It might be difficult to figure out how to change the icon resource of an existing file, but once known it should be easy provide the replacement and origanal are the same size.
Interesting: But, don't know how.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Try here[^].
Software Zen: delete this;
|
|
|
|
|
Hi,
I have done a project and it was working fine all these days. Finally I had to add one more function so I created a new toolbar and attached the function to it,but when I run, this new toolbar button is not showing up. I also added this item in the menu bar....after running it is not showing up....any idea why is it acting like this??? Please do help, i have a deadline. I am sure it is nothing to do with the project, so I was thinking is this something to do with the system files of vc++.
Thanks a lot
|
|
|
|
|
ashsri wrote:
I am sure it is nothing to do with the project, so I was thinking is this something to do with the system files of vc++.
Wrong!
I've been there too many times, always look at the project (source files) first.
(MFC 6.0 has a few minor (ligitimate) memory leaks).
-----------------------------------------------------------------------------
You can not attach a message function to a toolbar. A message function is
associated with a message, nothing more.
-----------------------------------------------------------------------------
What do you mean you created a new toolbar?
If that is actualy what you did, then you have to write code to switch to the new toolbar (or it will not show up), so you can use it.
Now I get the impression that you wanted to but did not add it to the existing toolbar.
Question: Did you create a new menu-bar the same way you created a new toolbar?
If you did, then you have the same problem in both places.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Hi,
I mean, I added few more items on the menu and the toolbar, to the one already existing. but it is not showing up when I run. I need not add any code, as I have already done it. So what I did was, just add or more items for the menubar and toolbar,and it is not showing up...thanks a lot for the help you are doing.
thanks
|
|
|
|
|
Hi all,
I'm using VS 6.0 to try and explicitly load a DLL. However no
matter what I've tried GetProcessAddress() always returns NULL.
LoadLibrary works fine (not NULL anyway). I've checked the exported
name from the DLL via 'depends.exe' and it's not mangled: it shows
the same name ("fnTestDLL").
I've googled for a couple of hours with no luck, so I'm
out of ideas. Maybe it's my project settings? I've tried
including the testdll.lib in "Link", the testdll.h in testp.app
and the DLL in "Debug" all with no luck.
I've dumbed-down my code to the basics and still can't get it
to work.
Any help would be greatly appreciated!!
------------------------------------------------------------
This is my App's "testapp.cpp" that (tries to) call my DLL:
------------------------------------------------------------
#include "stdafx.h"
#include "testapp.h"
#ifdef _DEBUG_
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CWinApp theApp;
using namespace std;
typedef int (CALLBACK* LPFNDLLFUNC1)();
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{ .............. }
LPFNDLLFUNC1 LibMainEntryPoint;
HINSTANCE LoadMe = LoadLibrary("c:\\code\\begin\\testdll\\debug\\testdll.dll");
if (LoadMe == NULL)
{ ............. }
LibMainEntryPoint = (LPFNDLLFUNC1) GetProcAddress(LoadMe, "fnTestDLL");
if (LibMainEntryPoint == NULL)
{ ....ALWAYS FAILS HERE!!!...........}
LibMainEntryPoint();
FreeLibrary(LoadMe);
return (0);
}
----------------------------------------
This is my DLL's "testdll.cpp":
----------------------------------------
#include "stdafx.h"
#include "testdll.h"
using namespace std;
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason, LPVOID lpreserved)
{
switch (ul_reason):
{
default: break;
}
return (TRUE);
}
TESTDLL_API int nTestDLL = 0;
TESTDLL_API int fnTestDLL(void)
{
return (42);
}
CTestDLL::CTestDLL()
{
cerr << "constructed";
}
CTestDLL::~CTestDLL()
{
cerr << "destructed";
}
-----------------------------------------------------
This is the DLL's "testdll.h":
-----------------------------------------------------
#ifdef TESTDLL_EXPORTS
#define TESTDLL_API __declspec(dllexport)
#else
#define TESTDLL_API __declspec(dllimport)
#endif
class TESTDLL_API CTestDLL
{
public: CTestDLL(void);
~CTestDLL(void);
};
extern TESTDLL_API int nTestDLL;
TESTDLL_API int fnTestDLL(void);
|
|
|
|
|
'Depends' has a 'C++' button in the toolbar. Make sure it's not pressed. A sure sign that the name is in fact mangled is if the full signature appears in the list, i.e. int fnTestDLL(void) .
Since you haven't wrapped the testdll.h contents with an extern "C" block, I suspect that the names are in fact mangled. You can perform an additional check using dumpbin /exports , which doesn't perform any translation.
You can fix this either by prefixing the 'flat' exports with extern "C" , or by using a module-definition file[^]. The latter is useful if you want to define a different external name from the name in the code, or if you want to specify the ordinal.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Thanks for the quick response. I don't see the C++ button you're talking about, but I'm using "Dependency Walker" version 1.0. It reports the name "?fnTestDLL@@YAHXZ" with entry point 0x00001082, which looks relatively correct to me, but I'm somewhat new to Windows DLLs, so maybe it IS mangled?
I'd prefer to stay away from EXP files if possible, simply because it should work without them.
|
|
|
|
|
The "?fnTestDLL@@YAHXZ" is the mangled name. The "@@YAHXZ" is the 'mangled' portion, and identifies the argument signature for the function.
Software Zen: delete this;
|
|
|
|
|
GetProcAddress(LoadMe, "fnTestDLL") fails becuase "fnTestDLL" does not exist in the DLL. [ GetLastError() ] No I am not kidding. If it failed the it is probably correct, so dig deeper.
Curriosity:
TESTDLL_API int nTestDLL = 0; // What is this for ( no given code uses it)
TESTDLL_API int fnTestDLL(void)
{
return(42);
}
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Thanks all!! By using the (ugly) name of "?fnTestDLL@@YAHXZ" instead of "fnTestDLL" it works fine. I think there are ways to export nicer sounding names for users of the DLL, which I'll have to look into, but at least now I can call this DLL. I can even create an instance of type CTestDLL now! (exported the public methods of the class, not the whole class, since apparently you can't export private class members/methods outside a DLL and exporting the whole class causes problems) Although the destructor doesn't seem to get called which is weird, but I'll read-up on that.
John> I included the "nTestDLL" because I'm trying to learn how to call DLLs, so I wanted to know how to export variables and not just functions. You're correct, my testapp doesn't currently use that variable at all.
Thanks again all for the help.
|
|
|
|
|
What is the include needed for graphics that is equivilent to the "#include <graphics.h>" in the Bordland Version of C++. Any help is appreciated.
Thanks,
Jon
|
|
|
|
|
There is no such thing in visual c. The graphics routines you are talking about are borland specific and are just an extension on code that borland wrote for Turbo Pascal about 20 years ago.
John
|
|
|
|
|
If we are talking windows programming than the basic drawing functions (GDI functions) are included when you include the windows header file (windows.h). For console based applications if you look at www.cprogramming.com some people have written custom graphics functions for use with console based apps. Just due a search from the main page.
|
|
|
|
|
|
With a MFC application I need to run a routine every 40msec.
Currently I am using the Standard Win32 Timers;
e,g, SetTimer(TIMER1, 40);
But sometimes it fires late.
I have the option to use an interrupt from a 3rd party PCI card. But as only 1 interrupt, could I use NAMED EVENTS to time actions on other applications, again with a resolution of ~ 40 msec.
e.g. Other applications with worker threads waiting for the EVENT to be fired via the interrupt routine.
Do you this will work on a PC 1.7 GHz processor, clock res = 1msec; with Windows 2000?
grahamfff
|
|
|
|
|
|
Hello !
Windows is not the best platform for time-critical applications. If you must use it, though, you could try increasing the priority of your application to maximum level. This ensures that the 40 ms (I assume milliseconds, here)timer is fired as close to 40 ms intervals as possible.
Increasing the priority of your application will cause other applications to lose theirs: increasing the accuracy of your application might/will cause inaccuracy/stiff response/high latency in other applications concurrently executing in the system. Pushing one application to real-time priority will most likely cause the operating system to appear 'locked up' while this single application is executing. The timer will reach as close to 40 ms intervals as possible, though. That's the price you'll have to pay.
When designing the real-time thread, you must make it as low-resource hog as possible.
For an example, create a thread, increase it's priority and call SetTimer Win32 API routine with a pointer to the function that should run at 40 ms intervals. Then put this thread into a forever loop that can be interrupted, if necessary. When interrupted, the timer should be killed and the thread terminated. Note that this will not cause the system to lock up, because the priority of the process itself has not been raised. You could use SetPriorityClass to pump up the process priority as well. Before doing this, familiarize yourself with Scheduling Priorities[^] in the MSDN or in Visual Studio documentation. Misusing thread or process priorities is a sure way to get your computer locked up easily.
To set max priority for your MFC application's main thread, use AfxGetApp() to get the CWinApp object pointer, and call CWinThread::SetThreadPriority() with a parameter THREAD_PRIORITY_TIME_CRITICAL through this pointer. CWinApp derives from CWinThread . MFC does not have a direct routine to pump up process priority. You'd need to use a mixed-mode call (CWinThread::operator HANDLE and SetPriorityClass ) to accomplish this.
A precisely 40 ms timer with not a single micro-second delay or advance is impossible in a modern operating system. For such a purpose, you'd need to design and implement a micro-controller or similar solution.
Named events are used to schedule interprocess actions, or interthread actions. For example, you could create an event object in a remote thread to mark when this thread has ran a single loop. When the event object is signaled, a loop is complete and the next loop is starting, if it's a continous system. Event objects can be global or local, determining how they are created. Global of interprocess, local for interthread should be your general rule.
Even if you used named events, you would need some method to set the event to a signaled state whenever 40 ms has passed. This will again lead you back to the timing issue and the timers. Named events is the easiest way to signal other threads or processes that your 40 ms interval has passed, though.
Hope this helps.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Timer (WM_TIMER) messages have the very lowest priority in Windows. Even paint messages have a higher priority than timer messages. You shouldn't expect reliable behaviour from these timers.
Windows offers two other timer facilities: multimedia timers and waitable timers. For the first see Using Multimedia Timers[^]. For the second see the CreateWaitableTimer[^] function.
Another alternative is to decide whether you really need that resolution. If you're simply trying to update a timer display, measure the actual elapsed time using GetTickCount .
It sounds like you're trying to write a real-time system. Windows 2000 is not a real-time OS - the interrupt latencies are simply not predictable. If this is what you're trying to do, either obtain a real-time kernel which runs Windows as a subtask, or use Windows CE.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
I would like to be able to capture a right click on a button. CButton doesn't seem to allow me do so, it only has click and double click messages. I tried creating my own button which was derived from CButton. The header file definition:
<br />
class CMyButton : public CButton<br />
{<br />
public:<br />
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);<br />
DECLARE_MESSAGE_MAP()<br />
};<br />
And then in my implementation file I have:
<br />
BEGIN_MESSAGE_MAP(CMyButton, CButton)<br />
ON_WM_RBUTTONUP()<br />
END_MESSAGE_MAP()<br />
<br />
void CMyButton::OnRButtonUp(UINT nFlags, CPoint point)<br />
{<br />
}<br />
With this, I capture all right clicks on the dialog, not exactly what I wanted. Is there a way for a button to capture right clicks? I would also like to capture left clicks, but that should be simple once I know how to capure right clicks.
Greba,
My lack of content on my home page should be entertaining.
|
|
|
|
|
Now that I've answered my own question
All I needed to do (it seems) was to add Default() in the OnRButtonUp(...) function. Like this:
<br />
BEGIN_MESSAGE_MAP(CMyButton, CButton)<br />
ON_WM_RBUTTONUP()<br />
END_MESSAGE_MAP()<br />
<br />
void CMyButton::OnRButtonUp(UINT nFlags, CPoint point)<br />
{<br />
Default();<br />
}<br />
Greba,
My lack of content on my home page should be entertaining.
|
|
|
|
|
Hi,
The problem is, prior of catching the button up message the button DOWN message must be handled!.
What you do, is catching all down messages, because when the mouse button is released your button provides the only handler for UP messages.
I know it's weird. But best is to react on the down message, setting a flag and in the UP handler do any action only if the flag is set. And always rest the flag.
GSte
|
|
|
|
|
Is there a regular repression class in VC++?
I would like to convert following VB code to VC++ code. Thank you.
<br />
Dim regexp As New Regex("<(B|b)(L|l)(O|o)(C|c)(k|K)(q|Q)(u|U)(O|o)(t|T)(e|E)")<br />
Dim matches As MatchCollection<br />
Dim m As Match<br />
<br />
'matches = regexp.Matches(body, "<\/(B|b)(L|l)(O|o)(C|c)(k|K)(q|Q)(u|U)(O|o)(t|T)(e|E)>")<br />
'If matches.Count > 2 Then <br />
'End If<br />
'm.index position is in the right position where <blockquote was found<br />
' therefore, substracting compund length of deleting <blockquote... > string from original match index <br />
'finding all the blockquote string and store in the array<br />
matches = regexp.Matches(body)<br />
If matches.Count > 2 Then<br />
Dim bquotes(matches.Count) As String<br />
Dim bquote As String<br />
Dim index As Integer = 0<br />
Dim count As Integer = 0<br />
<br />
For Each m In matches<br />
close1 = body.IndexOf(">", m.Index)<br />
Dim temp As String<br />
Dim found As Boolean<br />
temp = body.Substring(m.Index, close1 + 1 - m.Index)<br />
If index <> 0 Then<br />
For Each bquote In bquotes<br />
If bquote = Nothing Then<br />
Exit For<br />
End If<br />
If (bquote = temp) Then<br />
found = True<br />
Exit For<br />
Else<br />
found = False<br />
End If<br />
Next<br />
End If<br />
If Not found Then<br />
bquotes(index) = temp<br />
index += 1<br />
End If<br />
Next<br />
Dim i As Integer = 0<br />
For Each bquote In bquotes<br />
If (bquote = Nothing Or i = index) Then Exit For<br />
body = regexp.Replace(body, bquote, "")<br />
i += 1<br />
Next<br />
body = regexp.Replace(body, "<\/(B|b)(L|l)(O|o)(C|c)(k|K)(q|Q)(u|U)(O|o)(t|T)(e|E)>", "")<br />
body = regexp.Replace(body, "(M|m)(A|a)(R|r)(G|g)(I|i)(N|n)-(L|l)(E|e)(F|f)(T|t):", "")<br />
End If<br />
regexp = Nothing
|
|
|
|
|
Not in the language itself but there is a lot of free source code that will do what you want. Search this site...
John
|
|
|
|
|