|
Hello everybody
I am trying to launch "An All-Purpose Keyboard Hook"(http://www.codeproject.com/system/KeyHook.asp[^]) dll with my application, but not successful... I have no idea why dll doesn't post messages to my application. This is a source code:
***Thread.cpp***<br />
<pre>#include "stdafx.h"
#include "ThreadsApp.h"
#include "KeyHook.h"
IMPLEMENT_DYNCREATE(Thread, CWinThread)
Thread::Thread(){ theApp.FileWrite("Thread constructed\n"); }
Thread::~Thread(){ theApp.FileWrite("Thread destructed\n"); }
BOOL Thread::InitInstance()
{
InstallKeyHook();
KEYENTRY m_entry;
m_entry.nMessage = WM_MYTHREADMESSAGE;
m_entry.hCallWnd = (HWND)Thread::m_hThread;
m_entry.hHookWnd = 0;
m_entry.iCombKeys = 0;
m_entry.iIndicators = 0;
m_entry.iKeyEvent = 0;
m_entry.iMinVKCode = 0x00;
m_entry.iMaxVKCode = 0xff;
if(AddKeyEntry(&m_entry) != KH_OK)
{
theApp.FileWrite("AddKeyEntry failed\n");
return TRUE;
}
theApp.FileWrite("Thread initialized\n");
return TRUE;
}
int Thread::ExitInstance()
{
theApp.FileWrite("Thread clean up\n");
return CWinThread::ExitInstance();
}
void Thread::MyMessageHandler(WPARAM wParam, LPARAM lParam)
{
char data[64] = "";
itoa(wParam, data, 10);
strcat(data, " <<< WPARAM\n");
theApp.FileWrite(data);
}
BEGIN_MESSAGE_MAP(Thread, CWinThread)
ON_THREAD_MESSAGE(WM_MYTHREADMESSAGE, MyMessageHandler)
END_MESSAGE_MAP()</pre><br />
<br />
<code>***ThreadsApp.h***<br />
<pre>class ThreadsApp : public CWinApp
{
public:
ThreadsApp();
void FileWrite(char *data);
virtual BOOL InitInstance();
};
class Thread : public CWinThread
{
DECLARE_DYNCREATE(Thread)
public:
Thread();
virtual ~Thread();
virtual BOOL InitInstance();
virtual int ExitInstance();
void MyMessageHandler(WPARAM wParam, LPARAM lParam);
protected:
DECLARE_MESSAGE_MAP()
};
extern ThreadsApp theApp;</pre><br />
<br />
<code>***ThreadsApp.cpp***<br />
<pre>#include "stdafx.h"
#include "ThreadsApp.h"
ThreadsApp::ThreadsApp()
{
}
void ThreadsApp::FileWrite(char *data)
{
FILE *f;
errno_t err;
err = fopen_s(&f, "C:\\debug.txt", "a");
fprintf(f, data);
fflush(f);
fclose(f);
}
ThreadsApp theApp;
BOOL ThreadsApp::InitInstance()
{
FileWrite("Application initialized\n");
Thread* pThread;
pThread = new Thread();
pThread->CreateThread();
pThread->PostThreadMessage(WM_MYTHREADMESSAGE,1,NULL);
pThread->PostThreadMessage(WM_MYTHREADMESSAGE,2,NULL);
pThread->PostThreadMessage(WM_MYTHREADMESSAGE,3,NULL);
FileWrite("Waiting for the end of thread...\n");
WaitForSingleObject(pThread->m_hThread, 5000);
FileWrite("Program terminated...\n");
return TRUE;
}</pre><br />
<br />
So, what i am doing wrong? :^)<br />
I hope somebody will help :rolleyes:<br />
and thank you very much in advance :rose: :)<br />
<br />
<br />
-- modified at 10:15 Tuesday 31st October, 2006
|
|
|
|
|
Hi
What exactly happens when you run this app? Does the thread freeze when you call pThread->CreateThread();?
Tom
|
|
|
|
|
no, everything runs alright but thread doesn't get messages from *.dll as well as CWinApp can't get messages to...
when message is sent from main application to thread like this:
pThread->PostThreadMessage(WM_MYTHREADMESSAGE,3,NULL);
then everything is alright well almost everything but other issue doesn't matter while i am not getting messages from dll...
this is a dll implementation in thread or how to call that
m_entry.nMessage = WM_MYTHREADMESSAGE; // Our message ID
m_entry.hCallWnd = (HWND)Thread::m_hThread;// Send message to this window
i am not sure if this is right parameter to give for dll (HWND)Thread::m_hThread ?
in the original example it gives m_hWnd i think it is CWnd::m_hWnd its window handler, because dll sends a message into "Graphical" window, i don't want that window, i want invisible application, so creating CWnd class dosn't fits for me i think...
-- modified at 12:57 Tuesday 31st October, 2006
|
|
|
|
|
This line is a problem:
<br />
m_entry.hCallWnd = (HWND)Thread::m_hThread;<br />
In the file KeyHook.cpp the value hCallWnd is used in the function who's prototype is below to send a message to a window via a call to PostMessage. There is no way a thead handle will suffice in such a situation.
<br />
LRESULT CALLBACK KeyboardProc(INT nCode, WPARAM wParam, LPARAM lParam)<br />
Either, modify KeyHook.cpp to use PostThreadMessage or use a window to receive the messages.
Regarding windows, wanting an invisible app is no barrier to using a window in this instance. When you create the window call either ShowWindow or SetWindowPos to make it invisible. This will basically make the window just an easily used message loop, ideal for your purposes.
Tom
|
|
|
|
|
thank you for advice
i will try to create invisible window
|
|
|
|
|
Are there any alternatives to using SetWindowRgn() to create a rounded window. Or is there any way to speed up the process. There is too much flicker for my liking when the window is being resized and a new region has to be set.
|
|
|
|
|
waldermort wrote: There is too much flicker for my liking when the window is being resized and a new region has to be set.
handle OnEraseBkgnd method
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief And You
|
|
|
|
|
On Win 2K and later you can use a layered window. I haven't used it personally, but IIRC one of the goals of layered windows was to be faster than regioned windows.
|
|
|
|
|
Thanks for the tip, I will give it a try.
|
|
|
|
|
Hi every body,
I now try to develop an application that can help the administrator monitor user file operations such as copy, delete, rename... but I don't know how and where to start. Could you please show me how to.
Thank you for your kind help.
|
|
|
|
|
TPN wrote: ...monitor user file operations...
From where?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
TPN wrote: I now try to develop an application that can help the administrator monitor user file operations such as copy, delete, rename... but I don't know how and where to start. Could you please show me how to.
look at ReadDirectoryChangesW api
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief And You
|
|
|
|
|
How can I compile my program in 2 or 3 different languages using visual studio??
The main problem is the resources file (.rc): how can I, for example, use the same menu with the same IDs, changing only the strings (whithout re-write everything)
Is there a way??
Cheers,
Russell
|
|
|
|
|
in the property of your menu, check the language. then you can duplicate the resource, and set a language for each.
|
|
|
|
|
tnx tox,
... but 2 precisations:
1- to choose the desired menu during the compilation shell I ONLY set the language on the property Resource/General/Language
2- I suppose that in this way every time that I add a new menu item it appears only on the selected menu', not on the others...right??
Cheers,
Russell
|
|
|
|
|
1- the resource choosen will be the one at the same language as the system first.
2- yes, you have to add the correct translation in all the resources.
|
|
|
|
|
Hi All,
Is it possible to call a web service from a dll, or is there any funtion that exists to perform this action.
Thanks in advance
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
i use gSoap for this (Google it). it builds a set of proxy classes from your web service interface which handle all of the communication between C++ and the service. it can be extended to use compressed XML (with zLib) and HTTPS (with OpenSSL), if you need that.
|
|
|
|
|
Thank you Chris ... I'll check it out ....
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Hi,
I have the wmv file and a wave file. I want to add the wave file into wmv file. How can we achive this?
Regards,
Hemant.
|
|
|
|
|
Like I keep telling you. The Windows Media Format SDK is made for this. It's THE SDK for ASF
files, which is what a WMV file is.
|
|
|
|
|
While I can't write it and post it here, maybe I can point you in the right direction.
You'll need to read the video stream(s) (there could be more than one) and write them to to
the new file. At the same time you will read PCM samples from the wave file and write them
to a new, separate audio stream in the new file. For synchronizing audio and video you'll need
to handle the sample time (passed to IWMWriter::WriteSample()) somehow.
It's alot of code to post an example here but there is plenty of sample code in the Windows Media
Format SDK. The "WMVCopy" sample application is a good place to start.
Hope this helps,
Mark
|
|
|
|
|
Hi,
Thanks for your comments!.
Now I am using the Windows Media Format SDK for adding the wave file to wmv file. I have written the following code, but it is not allowing to add audio to me. It adds either audio or video and not the both. WHat may be the reason
public static void AddAudioVideo()
{
try
{
// Create a WMEncoder object.
WMEncoder Encoder = new WMEncoder();
// Retrieve the source group collection.
IWMEncSourceGroupCollection SrcGrpColl = Encoder.SourceGroupCollection;
// Add a source group to the collection.
IWMEncSourceGroup SrcGrp = SrcGrpColl.Add("SG_1");
// Add a video and audio source to the source group.
IWMEncSource SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);
SrcAud.SetInput("D:\\wmv\\input\\2006_10_16_13_9_49_759.wav", "", "");
IWMEncVideoSource2 SrcVid = (IWMEncVideoSource2)SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
SrcVid.SetInput("D:\\wmv\\output\\TestOutPut.wmv", "", "");
// Specify a file object in which to save encoded content.
IWMEncFile File = Encoder.File;
File.LocalFileName = "D:\\wmv\\output\\OutputFile.wmv";
// Choose a profile from the collection.
IWMEncProfileCollection ProColl = Encoder.ProfileCollection;
IWMEncProfile Pro;
for (int i = 0; i < ProColl.Count; i++)
{
Pro = ProColl.Item(i);
if (Pro.Name == "Windows Media Video 8 for Local Area Network (384 Kbps)")
{
SrcGrp.set_Profile(Pro);
break;
}
}
// Start the encoding process.
// Wait until the encoding process stops before exiting the application.
Encoder.PrepareToEncode(true);
Encoder.Start();
Console.WriteLine("Press Enter when the file has been encoded.");
Console.ReadLine(); // Press Enter after the file has been encoded.
}
catch (Exception e)
{
// TODO: Handle exceptions.
}
}
///////
}
Regards,
Hemant.
|
|
|
|
|
What language is that code written in?
*shrug*
|
|
|
|
|