|
Hi guys.
I need to run some IE instance...
I used CoCreateInstance() ... it worked good but I noticed that it uses always the same exe, so in my multithreaded application it uses always the same running instance, i see in my taskmanager always the same iexplorer.exe even if i run more than one browser. Instead i need to run multiple exe, one exe for every thread. As I read on msdn CoCreateinstance uses the same instance.
So how to run a new exe when i create a new instance???
IClassFactory* oby;<br />
CoGetClassObject(CLSID_InternetExplorer,CLSCTX_ALL, NULL, IID_IClassFactory, (void**)&oby);<br />
hr = oby->CreateInstance(NULL,IID_IWebBrowser2, (LPVOID*)&WebBrowser);
I tried this code...but it doesn't work, it uses always the same exe without running a new one.
Thanx!
|
|
|
|
|
Why are after running a new exe.
I will not happen, because windows always share resources.
Creating a new instance means that you are instanciating a new object.
If just want to run two copies of the same exe why not use ShellExecute function. I think this will help.
|
|
|
|
|
thanx for you answer...
i need to run multiple instances, evenif using the com object was surely lighter on system resource...so i used shellexecute and then link to the browser...
now it's ok!
|
|
|
|
|
I have a base class from which I derive several classes. Since I pass these derived classes to many functions, I decided the best approach is to specify the base class type in the function header. Is there any way to determine the derived class from a base class pointer?
class Base
{
};
class derA : public Base
{
};
class derB : public Base
{
};
void SomeFunction( Base* base )
{
}
|
|
|
|
|
As a rule, the code in SomeFunction shouldn't care what type of derived class is passed to it. If you need specialized behavior in SomeFunction , add a virtual function to the Base class that can be overridden in the derived classes:
class Base
{
public:
virtual void Behavior();
};
class derA : public Base
{
public:
virtual void Behavior();
};
class derB : public Base
{
};
void SomeFunction( Base* base ){
base->Behavior();
}
derA A;
derB B;
SomeFunction(&A);
SomeFunction(&B);
Software Zen: delete this;
|
|
|
|
|
That's basically what I implemented, but I was just wondering if here was an easier way to do it. Thanks anyway.
|
|
|
|
|
derA* einA = dynamic_cast<derA>(base);
derB* einB = dynamic_cast<derB>(base);
if(einA) {
} else if(einB) {
} else {
}
--
Verletzen zerfetzen zersetzen zerstören
Doch es darf nicht mir gehören
Ich muss zerstören
|
|
|
|
|
Hello.
We need to use UserControl components written in C# in our existing MFC application. The components need to be inserted into existing ActiveX controls (written using MFC and ATL as separate OCX files). The recommended way is to turn on the /CLR switch and use CWinFormsControl class. Using this approach I was able to insert a simple test component into one of our ActiveX controls and successfully build the OCX in Debug mode, however when running the application I noticed that when the app tries to create an instance of the modified ActiveX control it fails with the following error: ClassFactory cannot supply requested class. The same load failure occurs even when I completely removed the test component from the ActiveX control so it seems that the failure is caused by building with the /CLR switch. I also tried to build the ActiveX's StdAfx.cpp and the cpp file containing code for the ActiveX DLL (such as InitInstance and DLLRegisterServer) without the /CLR switch but it didn't help. The control is registered properly and w/o errors (at least that's what regsvr32 shows).
We use Visual Studio 2005, any help will be greatly appreciated. Thank you.
|
|
|
|
|
Have you been successful on using a C# UserControl with an unmanaged MFC ActiveX host container?
Similar to you, we need to use a C# UserControl and expose it as an ActiveX control. As far as I can see there are some completely different approaches. One would be using an unmanaged MFC ActiveX as host container for the Windows Forms control. And then using CWinFormsDialog or CWinFormsView to host the Windows Forms control. Another approach would be to rebuild the complete ActiveX interfaces with C# and expose it directly to COM.
We tried approach one and have some major problems. We created the MFC ActiveX host container which works and currently displays an empty CDialog. Now, when turning on Common Language Runtime support (/clr), Visual Studio 2005 locks up when loading the project. 100% reproducible... turning of '/clr' everything works, turning it on VS2005 locks up while loading the project without any error message, it just hangs while loading CLR dlls like 'mscoree.dll', 'mscorwks.dll'.
Any help would be appreciated... thanks in advance!
cheers,
mykel
If they give you lined paper, write the other way!
|
|
|
|
|
In my solution I would like to have 3 projects in C++ and the following architecture:
1. Interface.
It is a DLL that has only interfaces with pure virtual functions.
Some of those interfaces should also be singletones (I need to ensure that the concrete class will be singletone).
2. Implementation.
It is another DLL that implements concrete classes for those interface classes defined in Interface DLL. The Implementation DLL will load the Interface DLL.
3. TestDriver.
This is an EXE application that will know only about Interface DLL/LIB and will NOT LOAD the Implementation DLL. It will use the Interface like this:
Interface *my = InterfaceDLLClass.GetInstance();
The GetInstance will return an object of concrete class.
In such a way I will be able to change Implementation DLL in the future without changing Interface DLL and TestDriver EXE.
Is it possible to implement such an architecture in C++?
Can you give me some advise/link?
As I understood, in Java/C# it is possible, but I need C++.
Thanks in advance.
|
|
|
|
|
I think you may have a misunderstanding about DLL's. Your interface DLL as described can't exist. A DLL contains executable code that is loaded dynamically at run-time. A set of classes that contain only pure virtual functions by definition don't generate any code, since there is no implementation.
The whole point of using a DLL is being able to replace the code in the DLL without recompiling the entire application. That's why it's called a Dynamic Link Library. This meets your requirement to change the 'implementation DLL' in the future without changing the interface.
What you end up with is a header file that specifies the 'interfaces' (the classes) implemented in the DLL, and the implementation DLL. One of the functions in the DLL can return an instance of the object implemented by the DLL, thereby enforcing the singleton requirement.
For further reference, COM in the Microsoft Windows environment provides a lot of these sorts of features in an architecture that lets your application enumerate compatible implementations. With ordinary DLL's, they have to be in a known location, and the interface signatures must match exactly. COM gives you more flexibility, but at the price of a steep learning curve.
Software Zen: delete this;
|
|
|
|
|
Thanks a lot Mr. Gary R. Wheeler,
1. I understood what you wrote, but the whole point is not to load the Implementation DLL by the TestDriver project. Is it possible that the TestDriver will be aware only about the Interfaces?
2. Another important point is that my Interfaces contain pure virtual interfaces and some implementations as well, so I could not remain them just in header files. May be I should use static lib??
3. I tried to think in the direction of templates to solve the problem, but still did not come to any conclusion.
Thanks again, Julia1.
|
|
|
|
|
I think part of our stumbling block here is the notion of an 'interface'. AFAIK in .NET (C#) and Java, an 'Interface' is a concrete, compilable language feature that specifies how two pieces of code communicate. There is no corresponding language feature in a pure C++ DLL. An 'interface' is a descriptive term only. A DLL simply provides executable code with known entry points, described either through 'C' style function signatures or as C++ classes.
If I understand correctly, what you're trying to accomplish is to have your TestDriver program load an Interfaces DLL, rather than loading an Implementation DLL directly. What I don't understand is how your Implementation DLL will ever get loaded. In your original post, you state that the Implementation DLL loads the Interfaces DLL. You then have the TestDriver program and the Implementation DLL loading the Interfaces DLL, but no one loads the implementation DLL. For the Implementation DLL to be loaded, there has to be some code, either an application that references the Implementation DLL directly, or some DLL that is uses that references the Implementation DLL.
My point in my previous post was that I don't think you don't need to have two DLL's to accomplish your goal of being able to replace the Implementation DLL at will without having to recompile the TestDriver application. Have your TestDriver application use the Implementation DLL directly; no Interface DLL is required. You can replace the Implementation DLL as needed. As long as you don't change the function signatures or class definitions for the code implemented in the DLL, this will work correctly.
I'm sorry if I'm not understanding your situation exactly. I hope this explains my earlier reply a little better.
Software Zen: delete this;
|
|
|
|
|
Hey Guys,
I know the following might sound like a silly question, but I have a project which is a Doc-View SDI MFC project. Any way a requirement has emerged which means I need to use combo boxes in the actual view window.
Does anyone have any experience at using something like this, In particular can you use a combo box in the view class of an SDI app? If so how do you incorporate it.
Looking forward to your reply.
Best Regards
Danny Nowlan
|
|
|
|
|
have you looked at CFormView?
cje
|
|
|
|
|
Since controls are just windows you can use them as a child window on any window.
An easy way is to add a CComboBox member to your window class:
CComboBox m_MyCombobox;
Add a WM_CREATE handler to the window class. In the handler call Create() for the combo box.
int CMyWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
m_MyCombobox.Create(CBS_DROPDOWN, CRect(10,10,100,15), this, IDC_MYCOMBOBOX);
...possibly populate the combo box here using AddString() etc ...
return 0;
}
This example places a 100 wide by 15 high CBS_DROPDOWN style combo box at 10,10 in the window.
You could handle WM_SIZE in the window and move the combo box in response to the user resizing the
window.
Hope this helps get you started!
Mark
|
|
|
|
|
Hey Mark,
Thanks for that mate. I implemented it and I had no errors, however the Combo box still isn't showing up. I also created a IDC_MYCOMBOX resource with the type set to child. Any ideas?
For what its worth I am dealing with a view that is derived from CView as opposed to CFormView. Is that part of my problem?
Thanks again to everyone for all their help.
Danny
|
|
|
|
|
Danny Nowlan wrote: I implemented it and I had no errors, however the Combo box still isn't showing up.
Sorry The limited example code didn't have enough style flags.
try
m_MyCombobox.Create(CBS_DROPDOWN|WS_VISIBLE|WS_CHILD, CRect(10,10,100,15), this, IDC_MYCOMBOBOX);
Calling MyCombobox.ShowWindow(SW_SHOW) would make it show as well. Useful if you want to
create it hidden and show it later I suppose.
Mark
|
|
|
|
|
In my application I connect to a site and request a search. In the source code of the webpage the server sends back, there's a link I need to follow. I was thinking something like this would work:
connect
send: "GET /?name=example HTTP/1.1\r\nHost: example.com\r\nConnection: Keep-Alive\r\n\r\n"
retrieve the page returned and parse it
send: "GET /?id={what I parsed out} HTTP/1.1\r\nHost:example.com\r\nConnection: Close\r\n\r\n"
I retrieve the page like this:
void ReceiveDoneCallback() {
if (bytes read > 0) { read more }
else { parse message; generate second request; }
}
Now this works but not the way I want it to. It takes about 20 seconds before the server closes the connection. That is, when the Connection: Keep-Alive header is sent along. I think it's because I still call another BeginReceive while there's bytes read. I workaround could be to compare bytesRead to buffer->Length, but what if the output page is a multiple of my output buffer size?
Can someone tell me how this is done?
Thanks in advance,
Frank
|
|
|
|
|
Are you using WinInet for this? If so, call InternetQueryDataAvailable() to tell how many bytes of the response are waiting for you to read.
|
|
|
|
|
I asked around a bit and I was told that I need to read out the Content-Length header which the server sends back. I was very proud of myself when I got that done, but then I found out that's the length of the stuff that comes after the headers, and Content-Length isn't the latest header sent
Anyway, I also managed to fix that up. Here's the code I used.. if anyone ever uses the search button and finds this.
void ReceiveDone(IAsyncResult^ ar) {
Socket^ s = safe_cast<Socket^>(ar->AsyncState);
try {
int bytesRead = s->EndReceive(ar);
String^ read = Encoding::ASCII->GetString(buffer, 0, bytesRead);
sb->Append(read);
TimesRead++;
if (ReadingHeaders == true) {
Int32 index = sb->ToString()->IndexOf("\r\n\r\n");
if ((index != -1) && (ContentLength != 0)) {
TimesRead = 0;
sb->Remove(0, index + 4);
ReadingHeaders = false;
}
else if (ContentLength == 0) {
array<String^>^ seperators = gcnew array<String^>{"\r\n", ": "};
array<String^>^ headers = sb->ToString()->Split(seperators,StringSplitOptions::None);
Int32 index = sb->ToString()->IndexOf("Content-Length:");
if ((index != -1) && (index + 10 < sb->Length)) {
for (int i = 1; i < headers->Length; i++) {
if ((headers[i] == "Content-Length") && (headers[i+1]->ToString() != "")) {
Int32::TryParse(headers[i+1]->ToString(), ContentLength);
ReadsRequired = (ContentLength / buffer->Length);
if (ContentLength % buffer->Length > 0)
ReadsRequired++;
}
}
}
}
}
if ((ReadingHeaders == true) || (TimesRead < ReadsRequired))
sock->BeginReceive(buffer, 0, buffer->Length,
SocketFlags::None, gcnew AsyncCallback(this, &StatsSock::ReceiveDone), sock);
else
ParseDelegate->Invoke(sb->ToString(), this);
}
catch (Exception^ e) { MessageBox::Show(e->ToString()); }
}
|
|
|
|
|
I tryed SetFocus() but it didn't work.
Moreno
|
|
|
|
|
Use GotoDlgCtrl() instead.
example:
GotoDlgCtrl(GetDlgItem(IDC_MYCONTROL));
Mark
|
|
|
|
|
Hello everyone,
I am looking for an efficient way to implement matrix multiplication in C/C++. Are there any existing good ways?
The matrix is stored in an one-dimentional array.
thanks in advance,
George
|
|
|
|
|
Hello,
I'm trying to add the following lib: [url]http://id3lib.sourceforge.net/[/url]
to my VS2003 project, I don't understand the instructions:
[code]
B)***Your project wants to link id3lib static, and has mfc linked dynamic or has no MFC:
1) Rename config.h.win32 to config.h
2) include libprj/id3lib.dsp and zlib/prj/zlib.dsp to your workspace
3) make your project dependend on id3lib, and make id3lib dependend on zlib
4) Add /D ID3LIB_LINKOPTION=1 to your project options (settings, C/C++ tab)
5) Add the following include dirs to your program:
/I <path_to_id3lib>\\include /I <path_to_id3lib>\\include\\id3
6) (add your code which uses id3lib)
7) Try to compile, and see if you need any of the following:
(debug) /nodefaultlib:"msvcprtd" or(release) /nodefaultlib:"msvcprt"
(debug) /nodefaultlib:"MSVCRTD" or(release) /nodefaultlib:"MSVCRT"
(debug) /nodefaultlib:"libcmtd" or(release) /nodefaultlib:"libcmt"
different programs may require different 'nodefaultlib' 's, or none at all, these worked for me.
If none you try work, revert to C)
[/code]
Please help, without this lib I can't go on with my project.
Thank you.
|
|
|
|
|