|
As I see it there are three ways do accomplish this.
1. (Not very good and should be avoided until every other option has been rejected)
Poll some interface method that can inform the caller whether the server is up and running or not. Calls could be invoked by a timer.
2. (Presumably not suitable and requires a re-write of the server)
Have the server blocking while creating other servers so that it doesn't return until it's up and running.
3. (The correct way, if supported by the server)
Implement a callback, or connection point, that gets called when the server is up and running.
Technically there's a fourth way and that would be to cancel execution with ::Sleep(), but that is so very wrong that it doesn't even make the list above.
Don't even consider it!
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
Roger,
Thanks for the quick response.
I had thought about the Answer#1 and 3 and I thought 3 would be the best option. Let me check if I can implement #3 in the server - it's not owned by me
I had put the ::Sleep() in my client code and it works fine but as you said its not a good way and thats the reason why I am seeking for some other solution.
If you see any other solutions, do let me know.
Thanks again.
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
I figured out a simple solution for this. Place the call to
COleTemplateServer::RegisterAll();
after your server intializes and before it shows its window/dialog, if any.
If I am wrong, please correct me.
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Ummm, not sure actually...
From MSDN Remarks COleObjectFactory::RegisterAll: Registers all of the application’s object factories with the OLE system DLLs. This function is usually called by CWinApp::InitInstance when the application is launched.
I guess the above would make sense if you've written an EXE-server and the call to RegisterAll was omitted. Then it should definitely be added if I've understood MSDN correctly.
If you haven't made an EXE-server, then I don't know in what way this could be applicable nor how/why it would solve your initial problem.
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
I have an EXE server written in MFC!
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Sohail Kadiwala wrote: I have an EXE server written in MFC!
Ok, then it makes sense to add the call to RegisterAll() .
So it's all good then, right?
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
The call to RegisterAll() was present but before the server started other servers, inshort before it completely initialized its state. So I moved the RegisterAll() call after the initialization just before its main window is shown. The call to RegisterAll() informs the OLE System Dll's that the coclasses inside this server are ready to handle calls.
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
what is the use/function of manifest file in WTL
|
|
|
|
|
The manifest file is embedded into the executable to support the XP Themes.
|
|
|
|
|
hi i had found a project but this line give me confusion,if any body can help me i will be thankful to him.
std::vector<handle> vThreads;
HANDLE hThread = CreateThread(NULL,0,CMyService::Serve,(void*) pServe,CREATE_SUSPENDED,&dwServe);
vThreads.push_back(hThread);//i m talking about this line,
will that thread will be executed in backgroundor not,what will happen to that thread.
Tasleem Arif
|
|
|
|
|
The CREATE_SUSPENDED flag means the thread will not run until you call ResumeThread() on its handle.
|
|
|
|
|
tasleem143 wrote: vThreads.push_back(hThread);//i m talking about this line,
will that thread will be executed in backgroundor not,what will happen to that thread.
This line stores the handle returned by the CreateThread API.Which is helpful for controlling the thread.
And thread is created in suspended mode.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Thanks both of u for kind help.
Regards.
Tasleem Arif
|
|
|
|
|
i create an ATL project and insert an full control named IMyClient .the class is
CMyClient.Then i add other C++ class CDealEvent .Now i want to use the function 'onidle'
that in CMyClient ,how should i do? the code like this:
///////////////////////////////////
//MyClient.h
///////////////////////////////////
#include DealEvent.h;
class ATL_NO_VTABLE CMyClient:
public ......
{
...........
///////////////////////////////
//here i add a function onIdle
///////////////////////////////
public:
HRESULT onIdle(void);
CDealEvent* pEvent;
HRESULT FinalConstruct()
{
pEvent=new CDealEvent();
}
}
///////////////////////////////////
//MyClient.cpp
///////////////////////////////////
HRESULT CMyClient::onIdle(void)
{
//some code here
}
CMyClient::CMyClient():pEvent(NULL)
{
}
//////////////////////////////////
//add other c++ class DealEvent.h
/////////////////////////////////
class CDealEvent
{
public:
callonIdle();
}
//////////////////////////////////
//add other c++ class DealEvent.cpp
/////////////////////////////////
void CDealEvent::callonIdle()
{
//here i want to call ' onIdle ' that in CMyClient
//how should i do?
}
|
|
|
|
|
china.net wrote: void CDealEvent::callonIdle()
{
//here i want to call ' onIdle ' that in CMyClient
//how should i do?
}
You can use CComObject::CreateInstance , but I doubt, you need same instance, is it?
|
|
|
|
|
Hi,
I'm porting one of the dll from vc6 to vc8. In doing so I have created a complete framework to create a dll and subseqently add atl objects.
By default the framewaork adds the follwoing code in the main app file
class MyClassModule : public CAtlDllModuleT< MyClassModule>
{
public :
DECLARE_LIBID(LIBID_MyClassLib)
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_MYCLASS, "{7C00C752-3DA7-4CB9-B721-7F39F9FEDD2E}")
};
In previous versions of ATL CComModule _Module was used which has been replaced by CAtlBaseModule.
Problem:
In the current application there is an
extern CComModule _Module in stdafx.h
and definition in main app file as CComModule _Module .
The global object _Module is being used in other files which include the stdafx.h file.
These files call methods like _Module.GetModuleInstance () and _Module.GetResourceInstance ());
Questions)
1)Is a global object of this class MyClassModule to be created and will the same exact functions as used on _Module be used here too.
2)Also since the above derivation is in in my app file how will the class MyClassModule and the global object of it be visible to other projects in order to call upon the functions.
|
|
|
|
|
|
Hi everybody,
can anybody please direct me to a web site or an article (I could not find anything helpful) about how to make controls to be transparent. I use Visual Studio 2005 to make a Visual C++ dialog based application, and I use ATL only. Even though I specify a static control should be transparent, it is not. The background is static, it does not change, but neither static controls nor the captions of group box controls are rendered transparently.
Thanks for your help.
|
|
|
|
|
Okay, I found it:
I need to handle the message OnCtlColorStatic:
::SetBkMode((HDC)wParam, TRANSPARENT);
return (LRESULT) GetStockObject (HOLLOW_BRUSH);
and my static controls are all transparent.
But I can still not make group box captions to be trtansparent.
Thanks.
|
|
|
|
|
I have a class that I wrote I C# and I want to use it in a VC++ project without turning the C# class into a COM object. These are the steps that I've been given by a colleague:
I don't have code sample but I have steps how to do it. But my problem is how do I do step 9? Does anyone have a code sample of how to access the C# methods in VC++ through a type library??
Much appreciated!
L
1. Create a C# class
2. Generate a key for it - sn -k keyfile.snk
3. Put an assembly directive at top of file
[(Assembly: AssemblyKeyFile("keyfile.snk")]
4. Compile
5. regasm file.dll /tlb to generate the COM Type Library
6. gacutil -i file.dll to place file in GAC
7. Copy the generated typelibraries into the directory of your ATL/C++ project
8. #import file.tlb no_namespaces named_guids (look up the reff for exact syntax)
9. Compile ATL/C++ code and you will have access to the interfaces through the types in the imported tlb
|
|
|
|
|
malayalite wrote: I want to use it in a VC++ project without turning the C# class into a COM object
The steps you posted turn the C# class into a COM object
malayalite wrote: 5. regasm file.dll /tlb to generate the COM Type Library
malayalite wrote: 7. Copy the generated typelibraries into the directory of your ATL/C++ project
8. #import file.tlb no_namespaces named_guids (look up the reff for exact syntax)
9. Compile ATL/C++ code and you will have access to the interfaces through the types in the imported tlb
So first you say you don't want to use COM then you ask:
malayalite wrote: how do I do step 9?
So the two questions contradict each other, therefore, what is your question?
led mike
|
|
|
|
|
I am a beginner of ATL, so help me .
i made a ActivX control by VS2005, which will be used in web pages.This activex Control need
to call some script functions,but i just got DISP_E_UNKNOWNNAME,the error position labeled by //! ,why? help me.
code like this:
I create a ATL project(dll,merging of proxy&stub) insert a atl control,here are my
choices:standard control,apartment,dual,no aggregation,support connection points,
add any interface such as IObjectWithSite etc. appearance i just choice 'invisible'.
add variables:
IWebBrowser2* pBrowser;
IHTMLDocument* pHtmDoc;
CComPtr<IDispatch> pScript;
implement SetClientSite method:
STDMETHODIMP CActiveClient::SetClientSite(IOleClientSite* pClientSite)
{
HRESULT hr = S_OK;
IServiceProvider *isp, *isp2 = NULL;
if (pClientSite==NULL)
{
if(pBrowser)
{
pBrowser->Release();
pBrowser=NULL;
}
return E_FAIL;
}
else
{
try{
hr = pClientSite->QueryInterface(IID_IServiceProvider,
reinterpret_cast<void **>(&isp));
if (FAILED(hr))
{
throw(BSTR("QueryInterface:IID_IServiceProvider
failed!"));
}
hr = isp->QueryService(SID_STopLevelBrowser,
IID_IServiceProvider, reinterpret_cast<void **>(&isp2));
if (FAILED(hr))
{
throw(BSTR("SID_STopLevelBrowser failed!"));
}
hr = isp2->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2,
reinterpret_cast<void **>(&pBrowser));
if (FAILED(hr))
{
throw(BSTR("SID_SWebBrowserApp failed!"));
}
hr=pBrowser->get_Document((IDispatch**)&pHtmDoc);
if(FAILED(hr))
{
throw(BSTR("GetDocument failed!"));
}
hr=pHtmDoc->get_Script(&pScript);
if(FAILED(hr))
{
throw(BSTR("GetScript failed!"));
}
}
catch(BSTR error)
{
MessageBox(error,OLESTR("info"),MB_OK);
return hr;
}
catch(...)
{
MessageBox(OLESTR("Unknown error!"),OLESTR("info"),MB_OK);
return hr;
}
}
if(isp)
{
isp->Release();
isp=NULL;
}
if(isp2)
{
isp2->Release();
isp2=NULL;
}
CComBSTR szName("TestScript");
DISPID dispid;
//! here "GetIDsOfNames" ,i failed to get the dispid of
//! TestScript function
//! The error code is DISP_E_UNKNOWNNAME
hr=pScript->GetIDsOfNames(IID_NULL,&szName,1,LOCALE_SYSTEM_DEFAULT,&dispid);
if(FAILED(hr))
{
switch(hr)
{
case E_OUTOFMEMORY:
MessageBox(OLESTR("E_OUTOFMEMORY"),OLESTR("info"),MB_OK);
break;
case DISP_E_UNKNOWNNAME:
MessageBox(OLESTR("DISP_E_UNKNOWNNAME"),OLESTR("info"),MB_OK);
break;
case DISP_E_UNKNOWNLCID:
MessageBox(OLESTR("DISP_E_UNKNOWNLCID"),OLESTR("info"),MB_OK);
break;
}
}
DISPPARAMS dispparams;
memset(&dispparams, 0, sizeof dispparams);
dispparams.cArgs = 1;
dispparams.rgvarg = new VARIANT[dispparams.cArgs];
for( int i = 0; i < 1; i++)
{
CComBSTR bstr = "using Script";
bstr.CopyTo(&dispparams.rgvarg[i].bstrVal);
dispparams.rgvarg[i].vt = VT_BSTR;
}
dispparams.cNamedArgs = 0;
EXCEPINFO excepInfo;
memset(&excepInfo, 0, sizeof excepInfo);
CComVariant vaResult;
UINT nArgErr = (UINT)-1;
hr = pScript->Invoke
(dispid,IID_NULL,0,DISPATCH_METHOD,&dispparams,&vaResult,&excepInfo,&nArgErr);
if(FAILED(hr))
MessageBox(OLESTR("Invoke Failed!"),OLESTR("info"),MB_OK);
return hr;
}
/////////////////////html doc
<html >
<head>
<title>no title</title>
<!-- my ActiveX control -->
<object id="iCryOne" height="0" width="0" classid="clsid:83145F6D-9130-4CAA-AA7B-
65C2540E1B61" >
</object>
</head>
<script language="javascript">
function TestScript(msg)
{
alert(msg);
}
</script>
<body>
</body>
</html>
-- modified at 7:59 Wednesday 22nd November, 2006
|
|
|
|
|
Where do you get the error? Also, tick the "Ignore HTML tags in this message (good for code snippets)" so we can read the code proberly; it's hard to read code without indentation.
Steve
|
|
|
|
|
Hi,
I'm porting one of the dll from vc6 to vc8. In doing so I have created a complete framework to create a dll and subseqently add atl objects.
By default the framewaork adds the follwoing code in the main app file
class MyClassModule : public CAtlDllModuleT< MyClassModule>
{
public :
DECLARE_LIBID(LIBID_MyClassLib)
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_MYCLASS, "{7C00C752-3DA7-4CB9-B721-7F39F9FEDD2E}")
};
In previos versions of ATL CComModule _Module was used which has been replaced by CAtlBaseModule.
Problem:
There was an extern declaration as extern CComModule _Module in stdafx.h and definition in main app file as CComModule _Module .
How do I replicate the above behaviour in the new version. as CComModule is known to stdafx.h all other classes could use _Module. How do I use the global instance of MyClassModule in other modules.
|
|
|
|
|
CComModule was declared in ATLBase.h . So there was not any problem previously.
You may need to move MyClassModule class definition to separate header file.
And declare its object as extern in stdafx.h . Before that you need to include class header.
Or in other words adopt method in c++ to make visbile any global object across applicatin.
|
|
|
|