|
One approach would be to store all message processing objects in a std::map<> container. Although this will only give you a 1 to 1 relationship between the expected window message and the object which handles it you'll have a nice start to begin expanding. When you receive the device notification message you can retrieve the object for that message and then call the appropriate method to handle the operation.
void HandleDeviceMessage(UINT msg, WPARAM wParam, LPARAM lParam)
{
ProcObject *obj;
std::map<UINT, ProcObject*>::iterator iter;
iter = m_DevNotifyMap.find(msg);
if(iter == m_DevNotifyMap.end()) {
return;
}
iter->second->OnNotification(msg, wParam, lParam);
}
I am a lean mean ground beef machine!!!
|
|
|
|
|
Recently, I develop Internet Explorer browser extension.
To put it concretely,
During Browser Extension[^], I applied Adding Button[^] to launch for my application (aka MyApp).
After installation, I could not see MyApp button in IE7, IE8 default toolbar because new extension button attached last position in toolbar.
So, I want to ask to customer after installation and arrange MyApp button to first in toolbar. like below
"Can I arrange MyApp's button to first order in toolbar ?"
But, I don't find any idea, method that control browser button order in toolbar.
(I try to find button order information in registry and to control browser event.)
Anybody have idea?
ref msdn
Browser Extension[^]
Addinb Button[^]
|
|
|
|
|
I'm automating Word and when I call a function that doesn't return for a long time (for example a call to
app.Run(_T("FilePrint")); ) it tends to freeze the UI of my app until it returns from the call, so I tried to run this code from a worker thread, but then COM complains and throws an exception RPC_E_WRONG_THREAD - "0x8001010E: The application called an interface that was marshalled for a different thread."
How can I solve this problem?
btw, there's an explanation about RPC_E_WRONG_THREAD in MSDN - INFO: Explanation of RPC_E_WRONG_THREAD Error[^], but I couldn't figure out anything from it.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Could you do all of the automation, including creation of the Word object, on the worker thread?
Basically you're running foul of COM single-threaded apartments and things, I think. This article[^] explains them well.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I read the article about apartments and replaced CoInitialize(NULL); with CoInitializeEx(NULL, COINIT_MULTITHREADED); in both my threads, but it still gives me the exact same error "The application called an interface that was marshalled for a different thread."
It's not really necessary for me to use multiple threads, I'm just doing it because I don't want my UI to block while I'm waiting for the COM method call to return. Do you know if there is some way to make a non-blocking COM method call akin to PostMessage vs SendMessage (I might post this as a new question on the forum btw).
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
sashoalm wrote: It's not really necessary for me to use multiple threads, I'm just doing it because I don't want my UI to block while I'm waiting for the COM method call to return
Which is commendable...
sashoalm wrote: Do you know if there is some way to make a non-blocking COM method call
This[^] is the only thing I remember - and that a) needs support from the COM server (Word doesn't provide it) and b) can't handle automation interfaces (which is probably one reason WHY Word doesn't provide it).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
[I could have sworn I'd posted this message before...]
I've been playing with a little Excel automation sample I've got, adding a) Word automation, and b) multi-threading to it. I've ended up with this code that a) creates a Word instance on the main thread and b) calls that Word instance on a different thread. And the call succeeds, returning the expected value!
#include <boost/thread.hpp>
#import "libid:00020905-0000-0000-C000-000000000046" version("1.6") auto_search no_dual_interfaces rename("RGB", "wordRGB") rename("ReplaceText", "wordReplaceText") rename("FindText", "wordFindText") rename("ExitWindows", "wordExitWindows")
void GetActiveDocName(Word::_ApplicationPtr const& wd, _bstr_t& name)
{
try
{
name = wd->ActiveDocument->Name;
}
catch(_com_error& e)
{
name = L"No name";
}
}
int _tmain(int argc, _TCHAR* argv[])
{
CoInitializeEx(0, COINIT_MULTITHREADED);
{
Word::_ApplicationPtr wd;
if (SUCCEEDED(wd.CreateInstance(__uuidof(Word::Application))))
{
wd->Documents->Add();
_bstr_t name;
boost::thread getName(GetActiveDocName, boost::cref(wd), boost::ref(name));
getName.join();
std::cout << (char*)name << std::endl;
}
}
CoUninitialize();
return 0;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello!
I'm trying to make an internet monitoring application to log all the URLs visited by the user. Something like http://www.ematrixsoft.com/website-spy-monitor-software.htm
I tried using a sniffer library as suggested at http://www.codeproject.com/KB/IP/URLLogger.aspx
but had problems with HTTPS URLs because it seems that no only the content of the page is encrypted, but also the URL itself.
Do you have an idea of a "simple" method to catch all the visited URLs from any browser?. I can use a library (Free or not) if necessary.
Thanks.
|
|
|
|
|
televes wrote: Do you have an idea of a "simple" method to catch all the visited URLs from any browser?
No. Encryption is used to prevent exactly what you are trying to do. Since the URL may contain arguments for a GET operation the request and response headers are also encrypted. Attempting to subvert this is typically frowned upon as it becomes a potential exploit for use by Spyware.
I am a lean mean ground beef machine!!!
modified on Thursday, August 13, 2009 6:40 PM
|
|
|
|
|
|
No, not in the middle, in the client machine. In fact, I have discovered a library to do this:
http://www.komodia.com/index.php?page=interceptor.html
|
|
|
|
|
You don't need any library.
Just use COM (Notifications)
|
|
|
|
|
I have created MSI package of my product - using Install Shield 12. The package contains several redistributable files included - partially, Visual Studio 2005 ones.
A customer sent me the following complaint:
"We use corporate version of Norton Antivurus. After installation of your product, any right click on any folder in Windows explorer and many other interactions with Windows cause a prompt of installing missing Norton Antivirus components."
Does someone have any idea what is reason of the problem?
|
|
|
|
|
Sounds like you may be installing older versions of a redistributable file that Norton relies on. The first thing I would check is the file versions and then move to make sure that any files you are installing into the System32 folder actually belong there.
I am a lean mean ground beef machine!!!
|
|
|
|
|
Hi! I am using Visual Studio 2008, and am trying to put some custom code into a DLL whose source code is supplied by a third party. The third party code compiles fine, and everything is fine until I write a piece of code that calls rand(). At that point, when I compile, I get the error message:
error LNK2019: unresolved external symbol _main referenced in function __tMainCRTStartup (file is LIBCMT.lib).
I tried excluding that lib from the link, but that caused a bunch of other errors. Does anyone know how to resolve this problem?
|
|
|
|
|
The only reason that the C runtime should look for 'main' is if it thinks you're building an EXE. Make sure your project properties do actually say your building a DLL...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I checked that; it does indeed think it is a DLL, and in fact it makes a DLL quite happily when I comment out the lines that call rand().
|
|
|
|
|
Hi,
Do you have /GS (Buffer Security Check)[^] enabled? Can you disable this setting and let me know if your problem is fixed?
Thanks,
-David Delaune
|
|
|
|
|
I disabled it; that didn't help.
|
|
|
|
|
I create an instance of Word by
app.CreateDispatch("Word.Application");
In task manager I can see this has started winword.exe with these command arguments:
WINWORD /Automation -Embedding
But I want it to start with
WINWORD /a /Automation -Embedding
Is there any way to make CreateDispatch start word with: "WINWORD /a /Automation -Embedding" ?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Doubt it - I think those arguments are probably stored in the registry, under the registration information for Word as a local COM server. I guess if you wanted to hack the registry...but that's a bad idea, I think.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Well, I actually might have considered it (changing the registry before making the call to CreateDispatch and changing it back immediately after), but I think I can't do it as a limited user, because the key is in CLASSES_ROOT. I'm going to check on that. Anyway, thanks.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Further to my previous answer...
It just so happens that I have a little sample app that automates Excel, so I modified it slightly to a) automate Word as well, and b) call a method on a thread (I use Boost.Threads for this because it makes it so much easier than raw Win32 threads). This app is quite happy to make Excel or Word method calls on a thread other than the one that created the Word/Excel instance - here's the code (missing some #includes, but you get the drift):
#include <boost/thread.hpp>
#import "libid:00020813-0000-0000-C000-000000000046" version("1.6") auto_search no_dual_interfaces rename("DialogBox", "excelDialogBox") rename("RGB", "excelRGB") rename("DocumentProperties", "excelDocumentProperties") rename("SearchPath", "excelSearchPath") rename("CopyFile", "excelCopyFile") rename("ReplaceText", "excelReplaceText")
#import "libid:00020905-0000-0000-C000-000000000046" version("1.6") auto_search no_dual_interfaces rename("RGB", "wordRGB") rename("ReplaceText", "wordReplaceText") rename("FindText", "wordFindText") rename("ExitWindows", "wordExitWindows")
void GetActiveDocName(Word::_ApplicationPtr const& wd, _bstr_t& name)
{
try
{
name = wd->ActiveDocument->Name;
}
catch(_com_error& e)
{
name = L"No name";
}
}
void GetActiveWorkbookName(Excel::_ApplicationPtr const& xl, _bstr_t& bs)
{
if (Excel::_WorkbookPtr wb = xl->ActiveWorkbook)
{
try
{
bs = wb->FullName;
}
catch(_com_error& e)
{
bs = L"No name";
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
CoInitializeEx(0, COINIT_MULTITHREADED);
{
Excel::_ApplicationPtr xl;
if (SUCCEEDED(xl.CreateInstance(__uuidof(Excel::Application))))
{
xl->Workbooks->Add();
_bstr_t name;
boost::thread getName(GetActiveWorkbookName, boost::cref(xl), boost::ref(name));
getName.join();
std::cout << (char*)name << std::endl;
}
Word::_ApplicationPtr wd;
if (SUCCEEDED(wd.CreateInstance(__uuidof(Word::Application))))
{
wd->Documents->Add();
_bstr_t name;
boost::thread getName(GetActiveDocName, boost::cref(wd), boost::ref(name));
getName.join();
std::cout << (char*)name << std::endl;
}
}
CoUninitialize();
return 0;
}
This code, when run, displays correct names. So - it IS possible to call Word on a thread other than the one that instantiated it...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi,
I have a static pointer in a class and im allocating memory in heap in a static function..and that function returns the same pointer...
then im using that function in some other class...now when should i deallocate the memory in heap....in the destructor of the class where the static pointer belongs to...?
Please correct me if im wrong..
|
|
|
|
|
The first thing which is important to understand here is that the static member of a class is shared across all instances of that class. It means that if you destroy your pointer inside the desctrutor of your class, as soon as one instance gets destroyed, then you end up with an invalid pointers for all other instances.
And also, if you allocate that pointer inside a static function, each time the function is called, the pointer will be recreated (which will lead to memory leak), unless you check if it has already been created.
Is there a valid reason why you need to have this static pointer ? If yes, then you will need to destroy that pointer when you don't have any class instances anymore.
Could you please explain the scenario here ?
|
|
|
|
|