|
Hi,
I want to build a ATL wrapper on c++ class and would like to use that component in VB.
I insert an ATL class MyAWrapper
I add one property HRESULT String([out, retval] BSTR *pVal)
one method HRESULT ClearString() to IMyAWrapper.
IDL file shows it then in MyAWrapper.h
i put following c++ code
class foo
{
std::string m_str;
public:
foo(std::string bar, bool baz) : m_str(bar)
{
if (baz) throw std::exception();
}
std::string get_string(void) { return m_str; }
void clear_string(void) { m_str = ""; }
};
in ATL class.. class MyAWrapper I addfollowing code.
STDMETHOD(FinalConstruct)(void)
{
try {
m_pfoo = new foo("test", false);
}
catch (...) {
return E_FAIL;
}
return S_OK;
}
in MyAWrapper.cpp, I put
STDMETHODIMP MyAWrapper::get_String(BSTR *pVal)
{
// TODO: Add your implementation code here
if (pVal == NULL)
return E_POINTER;
std::string sTemp = m_pfoo->get_string();
*pVal = ::SysAllocStringLen(sTemp.c_str(), sTemp.length());
return *pVal ? S_OK : E_OUTOFMEMORY;
}
STDMETHODIMP MyAWrapper::ClearString()
{
// TODO: Add your implementation code here
m_pfoo->clear_string();
}
Please tell me Are these stpes OK??
or
where to put c++ code?
I can not compile the project.. I get around 34 errors one of which is
'std' : is not a class or namespace name
Pleasew tell me how to have this perfectly function.
Thanks
Lee
Leya
|
|
|
|
|
yang__lee wrote: std' : is not a class or namespace name
Probably, you forgot to include header, string in this case.
Prasad
MS MVP - VC++
|
|
|
|
|
Hi,
I am using CListBox on the Dialog using WTL, but i am unable to remove its flickering, when it get resized with Dialog. I am using CDialogResize for resizable layout for this app.
I have tried using WM_ERASEBACKGRND too but it wont help.
How is this flicker removed.
Regards,
R.T.
It is necessary once in one's life to put every thing in doubt, so far as possible, in order to reach the truth. DesCartes
|
|
|
|
|
Try using WS_CLIPCHILDREN with your dialog?
|
|
|
|
|
Already tried that :S. but of no use. Also i have already tried Other common methods concerning with windows properties. But i seriously think i have to override WM_PAINT, WM_DRAWITEM etc, but how is the main question.
Regards,
R.T.
It is necessary once in one's life to put every thing in doubt, so far as possible, in order to reach the truth. DesCartes
|
|
|
|
|
Respected, all i am trying a web page which needs to display clients computer name and local time in clients computer....when viewing a page stored in another server computer........plz help me
pokhrel rohit
|
|
|
|
|
Hi,
I have created a COM exe server using ATL8.0, where I have a connection point container interface that fires events for its clients (implementing sink). I am able to receive events at client side, but if I try passing an interface pointer(other than IUnknown) as an [in] parameter it becomes invalid at client side, that is, any method call on this pointer generates exception.
The same peice of code works perfectly fine with DLL server.
Can any one tell me the reason for this behaviour?
Is this problem due to different Address Space?
what is the solution to this problem?
Please Help.
Thanks in Advance.
Kavita seth
|
|
|
|
|
Hi, Kavita.
If your exe is operating as an out of proc server (i.e., your client code is not in the exe), then that would probably explain the different results. In a DLL / in proc scenario your client and server are operating within the same address space, and of course with an out of proc exe they're not. When you pass in a normal pointer (of any kind) from one program to another, it's going to be in foreign address space.
In general, I don't think that's your best way to go. Instead, consider doing a slight tweak to your code so that instead of passing back an interface pointer to the client, you instead just pass a param value back that tells the client, "now query for this interface on me and call it." Either way, the client calls the appropriate function, but this approach is more in keeping with the COM / QueryInterface way of doing things.
Hope this helps,
Chris
|
|
|
|
|
Hi Chris,
Sorry for such a late reply.
Thanks for your suggestion.
But I can not modify the IDL file as it is following some standards, hence my event has to pass the interface pointer.
One more update is there.
My client if written in VB6.0, is able to use that pointer.
But not my VC++ client.
So this appears not to be the problem of address space as VB client is able to call any of the methods of Server with the same interface pointer received along with the event.
Can you suggest any thing
Kavita seth
|
|
|
|
|
Hello Kavita,
Is the interface (passed in via the [in] parameter of the event method) a custom interface ? i.e. is it derived directly from IUnknown as opposed to being derived from IDispatch.
If so, one possible reason is that the Proxy/Stub DLL for the custom interface is not available. You need to build and register such a Proxy/Stub DLL.
For instruction on building and registering Proxy/Stub DLLs, please refer to my blog entry :
http://www.codeproject.com/script/profile/whos_who.asp?msg=1413206&id=24366#xx1413206xx[^]
Best Regards,
Bio.
|
|
|
|
|
Hello Kavita,
If you would like some sample codes demonstrating the Proxy/Stub concepts I mentioned in my earlier reply, please email me :
bio_lim_2004@yahoo.com
Best Regards,
Bio.
|
|
|
|
|
I using FindFirstFile in a while loop like:
while (hfind = FindFirstFile(TEMP,&FindFileData))
{
if (hfind == INVALID_HANDLE_VALUE)
break;
//Do some stuff with the file
}
This will work if i delete or move each file after finding or else it will contiuosly loop. Is there a method that would simply step through each file read and go onto the next so that i do not have to delete the original and when it reaches the last file in the directory then it will return?
Or is there a better way? BTW, these files are XML files.
Thanks,
|
|
|
|
|
You only need to call FindFirstFile() once, after that, call FindNextFile()
|
|
|
|
|
LCI wrote: while (hfind = FindFirstFile(TEMP,&FindFileData))
{
if (hfind == INVALID_HANDLE_VALUE)
break;
//Do some stuff with the file
}
Instead try the following
hfind = FindFirstFile(TEMP, &FindFileData);
if(hfind != INVALID_HANDLE_VALUE)
{
do
{
// Do some stuff..
hfind = FindNextFile(hfind, &FindFileData);
}while(hfind != INVALID_HANDLE_VALUE);
}
Cheers,
Suresh
|
|
|
|
|
Can anyone please help me or give me some sample code? I need to create an ATL COM service which has a dummy interface.. say. add 2 numbers.. After creating the service, i want to register it as a windows service. Then i want to create a client which connects to this service and uses the interface.. (adds 2 numbers)
I have searched online and there is not a decent article which explains the process step by step... Any help in this regard will be very useful.
Thanks in advance!!!!
|
|
|
|
|
Hi,
Create a ATL Project and choose service(EXE) type. The Wizard will generate code for you.
Add an ATL Simple object Like as you add ATL Simple Object to any ATL Project.
Implement your dummy methods or what ever you want.#
Build the project, Go to command prompt and type <exe name> -i to Install it as a Windows service.
In Client you can do a #import on this executable and you can use your dummay interface and methods.
Cheers,
Suresh
|
|
|
|
|
I have succeded in creating a service with a dummy interface.... Then in the client I have imported the header file of the service and defined the GUID's. Suppose i have an interface IFirst_ATL and it has a method addnumbers(), then how can i access that method. I am trying to create an instance of the service by
hr = CoCreateInstance( CLSID_First_ATL, NULL, CLSCTX_INPROC_SERVER,
IID_IFirst_ATL, (void**) &IFirst_ATL);
IFirstATL->AddNumbers(5, 7, &ReturnValue);
but this is not giving me the desired results. Can you please provide me a sample and successfully running code for accessing the methods of the service?
Thanks in Advance!
|
|
|
|
|
Seems that i have found out the problem.. I replaced CLSCTX_INPROC_SERVER with CLSCTX_LOCAL_SERVER in CoCreateInstance(). But now i am facing a different problem.
I have defined a method in my interface as.
STDMETHODIMP CFirst_ATL::AddNumbers(LONG x, LONG y, LONG* z)
{
*z = x + y;
return S_OK;
}
when i try calling this method from client as
hr = IFirst_ATL->AddNumbers(5, 7, &ReturnValue);
the method returns S_OK, but the value in ReturnValue is some garbage value. Can anyone please advice where have i went wrong?
Thanks!
|
|
|
|
|
VS2005 seems to prevent you from adding ATL Dialog class from the wizard. I found a work-around:
1.
DEFINE_GUID(LIBID_ATLDelmeLib,
0x288cd07e, 0x98a4, 0x4259, 0x9f, 0x38, 0x99, 0xaf, 0xc8, 0xa, 0xd0, 0x6e);
class CATLDelmeModule : public CAtlExeModuleT< CATLDelmeModule >
{
public :
DECLARE_LIBID(LIBID_ATLDelmeLib)
DECLARE_REGISTRY_APPID_RESOURCEID((UINT)0, "{288CD07E-98A4-4259-9F38-99AFC80AD06E}")
};
CATLDelmeModule _FakeAtlModule;
CAppModule _Module; 2.Use Project->Add Class, to add your new dialog class. Notice how VS2005 seems to agree with us now!
3.Comment back the line CATLDelmeModule _FakeAtlModule; if not it will conflict
Looking at '/VC/VCWizards/1033/common.js' can guide your for a few more trick.
Software Development Is Decision making.
|
|
|
|
|
Hello,
I need to use a map to stock inforamtion that containt 2 int like
class y;
class x
{
int a;
int b;
bool operator< (const x& w) const {
CString strthis;
CString strother;
strthis.Format("%d_%d",a,b);
strother.Format("%d_%d",w.a,w.b);
return (strthis<strother);
}
My operator that I have programed work but, I know that the solution is very bad and not very efficient.
How can I make a good operator < or were can I found some sample to learn about programing operator
Thank for help
AutreChien
|
|
|
|
|
NorGUI wrote: How can I make a good operator < or were can I found some sample to learn about programing operator
Well, there's nothing wrong with the declaration of the operator.
You should consider how negative values of x::a and x::b should be treated.
Your implementation may not give the result you expect if either of the variables were found negative.
Regarding how to make the operator more efficient you can try the following:
bool operator<( const x& w ) const
{
bool bResult = false;
if( a == w.a )
{
bResult = (b < w.b);
}
else
{
bResult = (a < w.a);
}
return bResult;
} This is how I think you want your operator to work given the code snippet you posted. It uses the integer values and saves the detour using CString which is quite expensive.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
I have a class
template<class T>
class foo()
{
template<typename T> friend ostream& operator<< (ostream& os, TestTemplateCollection<T>& r)
{...
}
int main(int argc, char * argv)
{
foo<T>;
foo<B>; //error c2995 operator<< allready defined
}
order doesn't matter both T and B work without the other is there something special you must do to friend template classes work. I do have the header in cased in a #pragma once statmen so its not in the preprocess output twice.
-- modified at 22:08 Tuesday 17th April, 2007
a programmer traped in a thugs body
|
|
|
|
|
I fixed this.
If any one wants to know
friend function of template classes should be defined outside the class definition but in the header file or you liker will crap its pants.
a programmer trapped in a thugs body
|
|
|
|
|
I have native C++ XMLTranslator (dll) built using VC8 compiler in VS2005 IDE.
This dll basically imports msxml4.dll as shown below:
#import "msxml4.dll" named_guids implementation_only
When native clients using VC6 compiler link to my XMLTranslator.lib I found below linker errors in imports:
XmltxtorTest.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class _com_ptr_t<class _com_iiid<struct="" msxml2::ixmldomdocument2,&struct="" __s_guid="" _guid_2933bf95_7b36_11d2_b20e_00c04f983e60=""> > __thiscall altova::CDoc::Load
FromString(class std::basic_string<unsigned short,struct="" std::char_traits<unsigned="" short="">,class std::allocator<unsigned short=""> > const &)" Debug/XmltxtorTest.exe : fatal error LNK1120: 2 unresolved externals
The export signature of VC8 dll:
class _com_ptr_t<class _com_iiid<struct="" msxml2::ixmldomdocument2,&struct="" __s_guid="" const="" _guid_2933bf95_7b36_11d2_b20e_00c04f983e60=""> > altova::CDoc::LoadFromString(class std::basic_string<unsigned short,struct="" std::char_traits<unsigned="" short="">,class std::allocator<unsigned short=""> > const &)
Basically the difference I found is the word "const" between imports and exports.
VC8 compiler exports additional const key word in whereas VC6 compiler doesn't expect const key word during imports.
How to make msxml exports/imports compatible across VC6 and VC8 compilers??
Thank you so much for any help in this aspect. I have been trying to get around this problem over a week.
Thanks again & Regards,
-- modified at 13:29 Tuesday 17th April, 2007
|
|
|
|
|
LIBs are not backward-compatible, since any version of the compiler/linker can change internal details that end up breaking compat with older linkers. You'll need to build a LIB yourself using VC 6.
|
|
|
|
|