|
The message registered with RegisterWindowMessage are valid only for a session.
You cannot use this for your case since a service runs as a different user than the application.
You can instead use a named event for your purpose.
Use CreateEvent[^] to open/create an event both the service and the application.
Now your application can wait on the event handle that will be set from the service.
Just remember to give a name for the last parameter to the API.
And also remember to prefix the name with "Global\" .
So you could typically you a name like "Global\my_message" .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Well, here's the thing.
1.I'm able to communicate from the app. to the service using the ControlService function but not the other way around.
2.You say that it is only valid for a session. But as you can see I've used RegisterWindowMessage in the service as well as app.(to get the same SYSTEMWIDE unique -that's what msdn says- value for my message both inside the service and the app.) So if the app is reloaded from another user's context the app will gather the value of the message again.
3.I've even had the values displayed in both my service and app and they are the same. Thus the message is definitely unique and visible to both.
4.I even printed a log of all the messages recvd by wndproc of the app but the broadcasted msg never reaches the wndproc despite being successfully broadcasted from the service.
As for your idea of using named events, I did that and again the same issue was encountered. The service says that the event was set but the application never captures the event. Just to confirm, while using CreateEvent I still do need to follow the escaping conventions right? i.e I used CreateEvent(NULL,0,0,"Global\\my_message") in the service and
CreateEvent(Nothing,0,0,"Global\my_message") in the app.(since vb.net doesn't need to escape backslash)
Here's the code:
HANDLE MY_EVENT=CreateEvent(NULL,false,false,"Global\\my_message");
SetEvent(MY_EVENT);
In vb.net:
Const SYNCHRONIZE As Integer = &H100000L
Dim MY_EVENT As Integer
Private Declare Function OpenEvent Lib "kernel32" Alias "OpenEventA" (ByVal dwDesiredAccess As Long, ByVal inheritHandle As Integer, ByVal lpName As String) As Integer
Private Declare Function WaitForSingleObject Lib "kernel32" Alias "WaitForSingleObject" (ByVal hHandle As Integer, ByVal dwMilliseconds As Integer) As Integer
Sub New()
InitializeComponent()
Me.TopLevel = True
Try
my_event_thread = New Thread(AddressOf MyEventWatcher)
Catch ex As Exception
MsgBox("Error in initializing! " + ex.Message)
Application.Exit()
End Try
End Sub
Private Sub MyEventWatcher()
Try
MY_EVENT = OpenEvent(SYNCHRONIZE, 1, "Global\my_message")
While True
WaitForSingleObject(MY_EVENT, INFINITE)
MsgBox("Done")
End While
Catch ex As Exception
MsgBox("Exception:" + ex.Message)
End Try
End Sub
What should I do now?Any ideas? Thanks for the help!
modified on Monday, August 10, 2009 3:22 AM
|
|
|
|
|
Hi thanks for all the advice. I've managed to take care of it. I had to make the service interactive in order to make my application visible to it and I found no other way of making it visible due to the different user contexts. So you were right But one thing that I haven't quite understood is, why didn't events work? I mean a "Global" event should not be hindered by contexts/sessions right? But even the global events raised by the service were not visible to my application. Can you explain?
|
|
|
|
|
I'm not exactly sure why global names with events didn't work.
I'm sure it should work because I have done the exact same thing to communicate between a service and an application.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
hmm..and did you make your service interactive or not? By the way, did you look at the code that I had posted, the one using global events? Just to be sure I did it right.
|
|
|
|
|
I used the following code to create a file, so that every user can read, modify, delete and write to it:
CreateFile(
m_szLogFilePath,
GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_DELETE | FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN,
NULL);
but when I log in with a user other than one in which I created the file, I can not save any modification in it neither delete it. any help?
Thank you masters!
|
|
|
|
|
I guess your proble is related with the NULL value of the fourth parameter, see [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
so what?
Thank you masters!
|
|
|
|
|
Provided my guess is correct (I'm not an expert about) you've to explicitely create a security descriptor, see [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You are probably right.
If you want to have EVERYONE permission, you need to create new security descriptor.
NULL says that the default ACL is used, i.e. only the user or someone with higher privileges (administrator for example) can change the file.
Try this:
SECURITY_ATTRIBUTES m_pSecAttrib;
SECURITY_DESCRIPTOR* m_pSecDesc;
m_pSecDesc = (SECURITY_DESCRIPTOR*)LocalAlloc(LPTR,
SECURITY_DESCRIPTOR_MIN_LENGTH);
InitializeSecurityDescriptor(m_pSecDesc,
SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(m_pSecDesc,TRUE,(PACL)NULL,FALSE))
m_pSecAttrib.nLength = sizeof(SECURITY_ATTRIBUTES);
m_pSecAttrib.bInheritHandle = TRUE;
m_pSecAttrib.lpSecurityDescriptor = m_pSecDesc;
It should create security descriptor with EVERYONE permission.
Instead of NULL, send &m_pSecAttrib.
Hope I helped.
|
|
|
|
|
Jusef Marzbany wrote: but when I log in with a user other than one in which I created the file, I can not save any modification in it neither delete it. any help?
What error message are you receiving?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hello all.
I'm again bringing up this problem because my last thread regarding this problem dissolves in lot's of thread here, Hoping to find answer this time.
I am extracting the data in "Simplified Chinese" from database and writing the data into file(Notepad).. In other words i'm making many LAN Files from single database. It works well, I'm getting right data in LAN Files...
Now the problem is that the project is pretty big and old applications are using GetPrivateProfileString to read from LAN files, But when they(applications) read "Simplified Chinese" LAN files they get Junk or question mark instead of Simplified Chinese characters.. Also when i tried reading and displaying using GetPrivateProfileStringW it works well but i cannot alter old applications code..
So my question is that, Is there any way i can read that data in simplified chinese using GetPrivateProfileString and able to display right data on GUI.
P.S
I make different LAN files using different language databases including "Traditional Chinese" and it works well, Only Simplified Chinese is creating problem.
Thanks.
modified on Friday, August 7, 2009 4:49 AM
|
|
|
|
|
It seems your old applications were ANSI. You should recompile them with UNICODE flag set instead.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Thanks for your reply, Yes they are in ANSI But i simply cannot change anything..There's lot of dependency.. Whatever i can do is in my code(Database to LAN)..
|
|
|
|
|
I'm not sure if it really can be done, but try looking at the different code pages[^]. See GBK[^].
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
I tried int iReturn = _setmbcp(936); also... But no suuccess
Anyone...
Thanks.
|
|
|
|
|
gothic_coder wrote: iReturn = _setmbcp(936);
I don't know what that is.
Anyway, if you're program is ANSI how can you read Chinese Simplified? Isn't it supposed to need Unicode or at least MBCS or am I wrong?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Yes it will better to change the project setting with UNICODE support.
ANSI characters only 256 they wont support any East Asian language.
Величие не Бога может быть недооценена.
|
|
|
|
|
The OP says that Traditional Chinese works in his first post.
P.S. I make different LAN files using different language databases including "Traditional Chinese" and it works well, Only Simplified Chinese is creating problem.
I really don't get it how it can work with an ANSI program, but he seems to say that.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Yes it work smoothly in "Traditional Chinese"... Trust me, Other applications which reads are ANSI based... I am really confused why it's not working in the case of "Simplified Chinese".
Thanks.
|
|
|
|
|
My program is in UNICODE, and other applications(Which read from LAN) as i mentioned earlier were written long back and in ANSI... But when i make "Traditional Chinese" lan files the applications read the right data and i get right data in GUI.. I'm writing the unicoded data in the file(notepad) in my program...
So isn't there any way for "Simplified Chinese".
Thanks.
|
|
|
|
|
|
Also when i tried "Traditional Chinese" LAN files in "Simplified Chinese" operating system, It shows everything in English..I mean when i check LAN files it is in "Traditional Chinese" but when applications read from LAN files and display on GUI, it shows everything in English.. The OS is Windows7..
Also in Win XP, The application shows the mixture of right data and "?", It must mean that whatever application understand it shows it and for the rest it shows "?"..
Thanks.
|
|
|
|
|
I have a CMFCRibbonComboBox (which is derived from CMFCRibbonEdit), and I've captured the event of the user selecting an item by overriding OnSelectItem. However I don't know how to capture the event of the user typing inside the edit box and pressing enter. I looked at CMFCRibbonEdit::OnKey, but it is not called. Should I place a message-map entry instead? In spyxx the class of the edit box is isn't "EDIT", but "RichEdit20A".
Here's my code so far:
class MyCMFCRibbonComboBox : public CMFCRibbonComboBox
{
public:
MyCMFCRibbonComboBox(UINT nID, BOOL bHasEditBox = TRUE, int nWidth = -1, LPCTSTR lpszLabel = NULL, int nImage = -1)
: CMFCRibbonComboBox(nID, bHasEditBox, nWidth, lpszLabel, nImage)
{
}
virtual void OnSelectItem(int nItem)
{
CMFCRibbonComboBox::OnSelectItem(nItem);
}
};
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Just override the rich Edit EN_CHANGE message.
It will be notified.
Величие не Бога может быть недооценена.
|
|
|
|