|
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 ?
|
|
|
|
|
ya ill explain....
i have function which calculates the font ie...
CFont* Temp::m_newFont=NULL;
void Temp::init(CDC*pDc)
{
NONCLIENTMETRICS ncmet;
ncmet.cbSize = sizeof(ncmet);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncmet), &ncmet, 0);
m_newFont=new CFont;
LOGFONT lf;
HDC hDC=pDc->GetSafeHdc();
SecureZeroMemory(&lf, sizeof(lf));
lf.lfHeight = -MulDiv(20, GetDeviceCaps(hDC, LOGPIXELSY), 72);
lf.lfWeight = FW_MEDIUM;
lstrcpy(lf.lfFaceName,ncmet.lfMenuFont.lfFaceName);
m_newFont->CreateFontIndirect(&lf);
}
and other function which returns pointer..
CFont* Temp::getFont()
{
return m_newFont;
}
where as the above 2 functions are static functions and m_newFont(member varibale) is a static CFont*...
and now im exporting this class using _declspec(dllexport)
and im using this class in some other process..as below...
where pDc is a CDC pointer..
Temp::init(pDC);
and when im trying to use
LOGFONT lf;
CFont* pFont=Temp::getFont();
pFont->GetLogFont(&lf);
lf.lfHeight value is garbage value.....instead of correct value
and when i used Quickwatch and see pFont i see m_hObject as 0x00000000
im not able to understand why it"s getting null..
and even i tried like instead of creating a static pointer i created static CFont object and in getFont() i returned address of the object ...but even that doesn"t help...
pls let me know..
|
|
|
|
|
Cedric Moonen wrote: 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
I've always thought that this is a bit misleading, it's really just a global variable/function, and the class acts only as a namespace. I've read that explanation about being "shared across all instances of that class" and I think it confuses people rather that give them an accurate idea of what a static member is.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Please help to solve these scenario of process waiting for execution in C++
Scenario is as follows
There is one parent process say P1 and 4 child processes say A B C D
Process A starts at 3:00 pm
Process B starts at 3:15 pm
Process C starts at 3:30 pm
Process D starts at 3:45 pm
Process A take 1 hour for completion and process B,C,D takes
10 mins for completion
At a time only one process is allowed to execute since
these process shared some common resources so at any point of time
only one process is allowed to execute. but these are scheduled job so
process B, C, and D must wait till process A get completes
so process B must wait till 4:00 PM for execution
and starts at 4:00 PM
process C must start at 4:10 PM after completion of process A and B
process D must start at 4:20 PM after completion of process A and B and C
so these sequencing also should maintained
B, C and D cannot start unless and until A is get completed and user dose not know how much time A will take so B,C and D must wait for completion of A and after A completes then and then only B,C and D execute in a same order
so how to implement wait mechanism for this scenario ?
Currently i have implemented a lock mechanism where first process A will create a lock file and process B,C and D will continuously poll this lock file and as soon as process A finishes it will release a lock on and whichever process acquires a lock first will get executed first but here sequencing is not maintained and process executes randomly
so what kernel objects like event, semaphore are needed to solve this scenario.
Where to store data (simple command line) when this process are waiting ?
How to maintain a sequence for excutation ?
please help to solve this scenario of process waiting for execution
-Thanks
modified on Thursday, August 13, 2009 9:46 AM
|
|
|
|
|
Given your description... I don't think you need much in the way of kernel stuff.
This is very loose code, as I don;t have my compiler handy,
struct Task
{
sometimestruct Time;
THREAD_ROUTINE Thread;
};
Task tasks [] = { { MakeTimeSomehow (1515), TaskA}, { MakeTimeSomehow (1600), TaskB}, ... { 0, NULL} };
for (nTask; tasks [nTask]; nTask++)
{
int nSeconds = TimeBetweenNowAnd (tasks [nTask].Time);
if (nSeconds < 0) nSecconds = 0;
Sleep (1000 * nSeconds);
HANDLE hThread = StartThread (tasks [nTask].Thread, ......);
WaitForHandle (hThread);
CloseHandle (hThread);
}
Job done!
I might just put in some abort flag too... I only expect this to give you an idea. The main trick is that a thread handle is waitable, just like events, semaphores, etc.
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|