|
HI All
I planned to write some string into the string table of an executable file's resource and then fetch it out.
Below are my code
int main(int argc, char* argv[])
{
HANDLE hResource;
hResource = BeginUpdateResource("c:\\setupexe\\debug\\setupexe.exe", true);
//Update the resources
TCHAR testStr[] = "aaaa";
if (NULL != hResource)
{
if (UpdateResource(hResource,
RT_STRING,
MAKEINTRESOURCE(106),
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
testStr,
sizeof(testStr)/sizeof(testStr[0])) != FALSE)
{
EndUpdateResource(hResource, FALSE);
}
}
//Getting the resource
HRSRC hRes;
HMODULE hLibrary;
hLibrary = LoadLibrary("c:\\setupexe\\debug\\setupexe.exe");
TCHAR strBuffer[256] = "\0";
hRes = FindResource(hLibrary, MAKEINTRESOURCE(106), RT_STRING);
if (NULL != hRes)
{
int errorCode = LoadString(hLibrary, 1680, strBuffer, 256);
}
FreeLibrary(hLibrary);
return 0;
}
The point is:
I can't not get the string I just put in there. What I've got are just garbage characters.
I would appreciate if you could give my any hints about this.
Thanks
-Paul
|
|
|
|
|
This is a _PAIN_
Strings are not stored in that way in the resource table, they are stored in string blocks. The value you pass to UpdateResource is the number of the string block you wish to update, not the string...
Each block consists of 16 strings, and is layed out in memory like this:
WORD LENGTH1
TEXT STING1
WORD LENGTH2
TEXT STRING2
etc.
You find the string block you want with the following formula
nBlockID = (nStringID / 16) + 1;
Thats not all there is too it though, as you have to pass a pointer to a block of memory to updateresource that represents a string _block_ not just the string, and you have to build that block of memory up your self.
It really is sh*t.
Thankfully, there is an example in MSDN.
Search for Stablupd.exe and you will find a sample that does just what you want, study it, then shout at M$.
|
|
|
|
|
Hi Diddy
Many thanks. I've found the sample code. It works. However, just as you've mentioned, this is really terrible to use.
Thanks again for your help
-Paul
|
|
|
|
|
No Problem
I tried to do a very simply app that had a config program with it that just set a couple of string entrys in the table ages ago, had about 3 months of searching till I found that then gave up because it's so damm naff.
|
|
|
|
|
dear ll,
is there any api which can be used to get info about the system.....i.e.
processor details, cpu temp, fan speed and motherboard information?
Regards and Thnx
rIsHaBh
|
|
|
|
|
For getting Processor information and processor features, use
GetSystemInfo () and IsProcessorFeaturePresent () functions.
But dont know how to get the cpu temp and fan speed.
Regards,
Jijo
________________________________
Yesterday is history,
Tomorrow is a mystery,
But today is a present.
|
|
|
|
|
i know the problem, but windows doesn't provide any API for getting this special information.
Don't try it, just do it!
|
|
|
|
|
Hi,
TAB Messages from child dialog is not going to child dialogs message queue,but it is to the parent windows!! So whenever TAB is pressed parent window gets the focus. How to get the control to the child dialog itself!
With Best Regards,
A.Ilamparithi
|
|
|
|
|
In MFC or Win32? If Win32 are the dialogs modeless or modal? If modeless, are you calling IsDialogMessage in your message loop?
|
|
|
|
|
Hi,
If I have two doc/views and I have some data in the second viewor document.
How do I get the data from the second view document if I am currently in the first view/document.
I must be doing the dynamic_cast wrong as it is non null but I can't access any local data from the class. Has any one got a small code fragment that explains how to get to another doc/view when inside a doc/view using the CDocTemplate stuff?
I used GetDocTemplate etc but now I would to get to the current view.
Thanks,
flip
|
|
|
|
|
Not sure if this is what you need to do.
In your document object use GetDocTemplate() . You can then iterate all the open documents of that type using GetFirstDocPosition() and GetNextDoc() . You can compare the returned pointer to this to see if you are looking at yourself. Once you have the pointer(s) to the other doc(s), you can iterate them for their view(s) using GetFirstViewPosition() and GetNextView()
If you are starting in the view, you need to use GetDocument() first of all.
Roger Allen - Sonork 100.10016
Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind...
|
|
|
|
|
Hello guys,
I am having this problem to access (more specifically, to change text) the statusbar directly or indirectly in a MFC worker thread of my dialogue-based application.
The status bar was firstly created in my main dialogue class' OnInitDialog().
m_statusbar.Create(this);
m_statusbar.SetIndicators(indicators, 2);
m_statusbar.GetStatusBarCtrl().SetBkColor(RGB(180,180,180));
m_statusbar.SetPaneText(0, "Offline");
SetTimer(100, 1000, NULL);
The m_statusbar is a CStatusBar type member in the class declaration.
CStatusBar m_statusbar;
As I need to change the text in some functions in other classes and threads, I tried to make the statusbar accessible globally by having
pStatusBar = &m_statusbar;
also in the OnInitDialog, where CStatusBar *pStatusBar is declared as a global variable.
While there was no problem with compilation, but I'd encounter assertion error if I try to use pStatusBar to change text of the statusbar in the thread function, whether directly or indirectly (uses the change statusbar text function in other class), examples below:
UINT doPrintingProc(LPVOID param)
{
COtherDlg *ptr = (COtherDlg *)param;
pStatusBar->SetPaneText(0, "Testing");
ptr->ChangeStatusText("Testing");
}
I use the similiar way to manipulate the globally accessible CListView and CEdit text box, all seem to have no problem.
Would appreciate if someone could point out where I have done wrong.
|
|
|
|
|
I suspect your CStatusBar is doing a sanaty check and your blowing up in a ASSERT_VALID(this) call somewhere in CStatusBar. One of the things MFC classes often do is check for themselvs in handle maps when you call various mathods on them - the long and short of it is not all MFC classes can be passed around between threads in this way, and there is nothing you can do about it directly.
what you have to do is to use messages to communicate between the threads.
Declare a custom message:
#define WM_CHANGESBTEXT WM_USER+0x400
Add a hander for it to your dialog:
class CMyDialog:
{
LRESULT OnChangeSBText(WPARAM, LPARAM);
.
.
.
};
Wire up the message map:
BEGIN_MESSAGE_MAP(CMyDialog...)
ON_MESSAGE(WM_CHANGESBTEXT, OnChangeSBText)
...
Then implment the method:
LRESULT CMyDialog::OnChangeSBText(WPARAM wp, LPARAM)
{
LPCTSTR pszText = (LPCTSTR)wp;
m_statusbar.SetPaneText(0, pszText );
ChangeStatusText(pszText);
return 0;
}
Then in the thread, rather than do it directly, just send a message to the main dialog
UINT doPrintingProc(LPVOID param)
{
LPCTSTR pszString = "Testing";
AfxGetMainWnd()->SendMessage(WM_CHANGESBTEXT, pszString);
}
Dont forget to use Send (not post) message if your string can go out of scope.
}
|
|
|
|
|
Thanks alot, Diddy,
it works out nicely except a small fix for me to get it compiled -
AfxGetMainWnd()->SendMessage(WM_CHANGESBTEXT, (WPARAM)pszString)
As you have pointed out, not all of MFC classes can be passed around among the threads. But for those they do work out no trouble (direct pointer passing), is it safe to do it that way and not changing to SendMessage? This brings my another question. From what I'm thinking of SendMessage() now, it allows one thread (or class etc..) to basically send command the other class to perform its specific function(s), with options to also pass some desired data along. In my case, the changing of statusbar's text is done by its belonging class (my main class) with the original statusbar member. Therefore, no confusing pointer is there. Is it correct?
Thanks again for the help
really appreciated
Johnny
|
|
|
|
|
J.B. wrote:
it works out nicely except a small fix for me to get it compiled -
Arr well, when you write code without a compiler one error isn't bad i suppos
As a general rule of thumb, it's only the classes that interact with Windows etc that will cause you problems (this isn't a golden rule by anymeans) and out of those window classes, it's the ones that are more than just a thin wrapper round the Win32 API that cause problems. For example, CEdit is just a very thin wrapper around a edit control, and works fine, as you found out CStatusBar is more than that - and gives you problems. Its usually the classes that do anything at all with handle maps that don't work - as these are always local to the thread, and since your control is subclassed (by means of a DDX_Control statment) in your main thread,it's handle resides in that threads handle map.
As for the ones that do work - yes, it is safe to use them, but - you have the usual thread issues to think about. MFC classes are thread safe at the class level, but not the object level - IE to different instaces of a the same class provide no problems, but sharing the same instance might. It really depends on your app. You may find you need to use critical sections or other thread sync primatives to protect your control across threads, but you may be able to do without. It's all about thinking about what each thread is doing to the control - usually if one thread is just updating some text in the control, and the other is showing that text, you can get away without them. Where as if both theads are say updating the control's text, you shoud use a critical section to ensure they don't access the control at the same time.
J.B. wrote:
In my case, the changing of statusbar's text is done by its belonging class (my main class) with the original statusbar member. Therefore, no confusing pointer is there. Is it correct?
Sorry, but I really don't unstand what you mean by that?! Is what correct?!
|
|
|
|
|
Diddy wrote:
J.B. wrote:
In my case, the changing of statusbar's text is done by its belonging class (my main class) with the original statusbar member. Therefore, no confusing pointer is there. Is it correct?
Sorry, but I really don't unstand what you mean by that?! Is what correct?!
Thanks for the reply again, Diddy.
As you stated here that the classes that are always local to the thread don't work well, SendMessage() can be used to let one class to tell the other class (of the statusbar member) to perfrom some functions *locally*. And so it'd work. Whereas my original method was trying the directly access the member residing in one thread from another thread. I just want to make sure I've understood that what SendMessage() actually does A communicate link where different classes or threads will talk to each other and ask to perform some local functions.
Thanks,
Johnny
|
|
|
|
|
Hi i am deveoping namespace extension and i want to have web view kinda interface on my view side, For that which interface should i implement ?
Thank You.
Toughest Steel Comes From Hottest Furnance
|
|
|
|
|
plz give me example on creating web server that can serve dynamic page. I've already succeded using CreateProcess on C++ to serve PHP page. But how can i serve ASP page? are there ASP on windows that can be treated like CGI? or I must use ISAPI filter
If i must use ISAPI to serve ASP, plz give some advise or example!
THX A LOT, I REALLY NEED IT (for school task)
donald
|
|
|
|
|
If you want to server ASP, you should install IIS, it comes free with Windows 2000, and XP Pro. But you should also ask your class to move into the 21st century, ASP is dead, and good thing too.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
no no...you don't know what i meant. I want to create(write code) web server using c++. just like IIS, but it can run independently(on diff port). now i want my web server can accept ASP or PHP page like what IIS does.
yeah, my school is a little bit ....but, that's the homework. thx anyway.
donald
|
|
|
|
|
Could anyone give me an example?
|
|
|
|
|
Simple.
You use RegisterHotKey to register a new, global, system wide hotkey that can be used to send a predefined WM_HOTKEY message to the targetted window.
For example, this code piece creates a hotkey ALT+Z for the calling thread.
RegisterHotKey(NULL, 0x0010, MOD_ALT, VK_Z); Now, whenever you press ALT+Z, a WM_HOTKEY message is generated and posted into the calling thread's message queue. You can then create a message-map entry for MFC applications using
BEGIN_MESSAGE_MAP( CMyWindow )
ON_MESSAGE( WM_HOTKEY, HandleHotKeyPress )
END_MESSAGE_MAP See ON_COMMAND for information about the declaration of the handler function. It generally is a function taking two parameters of type WPARAM and LPARAM and returning a UINT or a boolean value. It might also return nothing.
You should store the hotkey identifier (0x0010) into a global variable, like a const UINT . This way you can call the UnregisterHotKey by using a constant instead of a raw number. Always remember to call the unregistration function when you no longer need the hotkey. Otherwise your application will fail to register a hotkey, because it's already reserved. Also, keeping the hotkey association active without having the target handler available may cause a system crash on Windows 95/98/Me.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thanks, Antti.
I create an HandleHotKeyPress like this:
void CMainFrame::HandleHotKeyPress ()
{
MessageBox("aa");
}
It work with debug build, but crash when the second I press the hotkey with Release Build. What's the problem?
|
|
|
|
|
Hi,I'm looking for the way of getting information of Status of Object such as object creation,activation,deactivation etc..
I thought It would be possible to get that infomation Using CLSID of the Object.
But I couldn't find it at all.
Please Help me..
Any idea will be helpful.
|
|
|
|
|
You're obviously talking about COM+ ? Why not just create a log file in your class, and then write to it when those events are called, with a timestamp ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|