|
I'm a VB programmer who is trying to convert an old C console application to a C++ ATL COM DLL for use with a VB GUI.
Good luck, you'll need
I've done async multithreaded programming in VB, and believe me: it's ugly, and for seasoned C++ COM programmers. MS says: "VB clients are monothreaded."
Well, you'll face 2 main problems, and I would start learning this topics to acomplish this:
- Building a message loop.
- Synchronizing Win32 objects: Events
- marshalling interface pointers between threads
If you fail to use them, your code will hang, or your code will cause a GPF.
Tip: You'll need another thread that creates the object and stay forever in a message pump.
Furor fit laesa saepius patientia
|
|
|
|
|
I've created an ATL COM - dll - MFC Supported with the AppWizard and I added a function that return a CString.
Now I want access to this function from another application to do it I type the next code.
In the ATL COM
...
__declspec(dllexport) CString GetEncodedText(CString p_sPlainText);
...
In the other application
...
hDLL = AfxLoadLibrary("BabMD5.dll");
if (hDLL != NULL) {
typedef CString (CALLBACK *ENCODETEXT)(CString);
ENCODETEXT p_encodeText = (ENCODETEXT)GetProcAddress( hDLL, _T("GetEncodedText"));
if ( p_encodeText != NULL) { // -> NEVER GET HERE
strEncoded = (*p_encodeText)( strPlain );
}
AfxFreeLibrary( hDLL);
}
...
Anybody knows what's happen? Why I can't get the function?
Thanks in advance
|
|
|
|
|
If your DLL is COM this is not the way to do it. Think COM not WIN32.
You need to create an instance then call the method.
CMyObject MyObj;
CoCreateInstance(__uuidof(myobj), .... )
BSTR bstrText
HRESULT hr = MyObj->GetEncodedText(&bsrText);
Notice also that you need a BSTR not CString. Since you are using ATL I'd also loose the MFC support, it doesn't get you anything but more overhead.
|
|
|
|
|
Hi,
While trying to create an object from the client ( remotely) i get the "Access denied" error. I have made sure that the security setting are correct by giving myself full control, that didn't help.
This used to work until i modified the dcomcnfg setting to run application on local computer as well as the remote one ( basically i checked both boxes, after restoring original setting hell the Access denied error started appearing.
any ideas??
* i know i have access to the remote machine as i have access to files on it through explorer.
Alii
|
|
|
|
|
Register the Server.exe and its proxy.dll (if available) on the client machine too. Then you can delete those two files from the client machine. It maybe work.
|
|
|
|
|
Salam,
Actually we've faced such problem before, and everytime we do somthing to solve this problem, and at the end, we don't document what we have found. But the last time we solved this problem, we made a decesion that we have to document this DCOM Access Denied problem thorouly. I have a Word Document (.DOC) which has the complete steps to configure the source and the destination machines which containes the DCOM component.
I'll try to attach this document to this site soon after I refine it . Please, keep track within the coming two days to find this document.
Regards,
ShadiK.
Shadi Al-Kahwaji
|
|
|
|
|
The article has been posted:
http://www.codeproject.com/useritems/dcomcnfg.asp
Enjoy it,
ShadiK.
Shadi Al-Kahwaji.
|
|
|
|
|
Hello,
Can somebody give me the advantages/disadvantages of using VB to develop COM component instead of using ATL to do the same. Any links to such comparisons are also appreciated.
Ganesh.M.Ramaswamy
|
|
|
|
|
Advantages:
Any idiot can code VB COM components.
Disadvantages:
Only idiots code VB COM components.
Furor fit laesa saepius patientia
|
|
|
|
|
nice one, daniel.
Sorry ganesh I do not have any links to pass on. As it must be obvious to you, in VB you don't really get a taste of what is COM. In VC++/ATL you get to meddle around with the inner working's of COM and get a real feel of how complicated COM actually is.
I'm an alien, I'm an alien
it's a beautiful life....
Bush
|
|
|
|
|
Ease of development v's tighter (better;) ) code.
|
|
|
|
|
Hi All,
I am developing an application which uses SQL Server CE as the database, from which I need to synchronize the data to the SQL Server on the server machine. When I tried to synchronize the data using the emulator, it worked perfectly. But, when I tried the same application on my iPAQ pocket PC, I got an error, "DLL for the class not found". When I debugged, the CoCreateInstance() method fails and returns the HRESULT with the error code corresponding to this error message. When I checked the CLSID on the registry, an entry was there in the registry and the corresponding DLL was there in the /Windows directory . Could any one help me to come out of this problem. Any help on this highly appreciated.
This is the line of code I wrote:
hr = CoCreateInstance(CLSID_RemoteDataAccess, NULL, CLSCTX_INPROC_SERVER, IID_ISSCERDA, (LPVOID *)&m_pRda);
Jabir
|
|
|
|
|
hello
i have this com function (using ATL):
STDMETHODIMP Cmanager::iniGetString(BSTR sSectionName, BSTR sKeyName, BSTR sFileName, BSTR *sRetVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
char sTemp[MAX_PATH];
memset(sTemp, '\0', MAX_PATH);
GetPrivateProfileString (_bstr_t(sSectionName), _bstr_t(sKeyName), "none", sTemp, MAX_PATH, _bstr_t(sFileName));
sRetVal = SysAllocString ((OLECHAR *)sTemp);
return S_OK;
}
the sRetVal return nothing.
how can i return sTemp?
|
|
|
|
|
Hi,
Try using the .copy member of the _bstr_t class. Something like this has worked well for me:
STDMETHODIMP XXX::get_String(/*[out, retval]*/ BSTR* pVal)
{
HRESULT hr;
_bstr_t aBstr = "Hello!!";
*pVal = aBstr.copy();
return S_OK;
}
|
|
|
|
|
There are two problems with the code. First, sRetVal is a pointer to a BSTR, so assigning to sRetVal won't do anything. Second, sTemp isn't a Unicode string, so casting it to (OLECHAR*) will give you unpredictable results. You can use CComBSTR to handle the memory allocation and character set conversion:
CComBSTR bstr ( sTemp );
*sRetVal = bstr.Detach();
--Mike--
http://home.inreach.com/mdunn/
Trillian: What are you supposed to do with a manically depressed robot?
Marvin: You think you've got problems. What are you supposed to do if you are a manically depressed robot?
|
|
|
|
|
Hello everyone!I am Sree Ram working on COMAddins for Word2000 and Excel2000.I have programmatically added a Command Bar and Menu Bar (and menu items) for both Word2000 and Excel2000.The button Handlers for these r working properly according to the code.My problem is both the Word and Excel are giving a macro security warning.The Word2000 is saying "the macro cannot be found or has been disabled because of your Macro Security settings" and the Excel2000 is saying "The macro cannot be found".I added the command bar and menu bar programmatically using ATLCom.I changed the security level by using tools/macros and templates and security.But this didnot solve my problem.Can anyone who has previously solved this problem or is able to solve this problem kindly help me to solve this problem.Please reply back to me.
Bye
Thanking You,
Sincerely,
Sree Ram
|
|
|
|
|
Does the MFC classes CFtpFileFind and CFtpConnection support timeouts?
I'm an alien, I'm an alien
it's a beautiful life....
Bush
|
|
|
|
|
CFtpFileFind don't need Timeout because is a boolean, the file is there or not...
CFtpConnection, have a own timeout, You can't set the timeout time. I think that the timeout can be seted in the registry.
Cheers!!!
Carlos Antollini.
Happy Friday
|
|
|
|
|
I am trying to instantiate a COM Server on a remote machine without
configuring either the client or the server machine via DCOMDNCFG.EXE.
Basically, the COM Server will NOT be registered on the client machine, but
only registered on the server machine. The calling client is a VB COM
object trying to remote another COM object. I have it working with some
objects that I wrote... but I cannot get it to work with the SQLDMO objects
(Server/Restore).
I found some information on the web for doing something similar, but it only
worked if you had a dummy COM server with the same interface registered on
the client machine so that when calling CLSIDFromProgID(), the call would
succeed in retrieving the CLSID for the later call to CoCreateInstanceEx().
I changed it to pass in the CLSID so I didn't need the call to
CLSIDFromProgID(), and I convert it to a UUID structure for passing to
CoCreateInstanceEx(). It works with some other VB objects I wrote... and
at first, I thought it was because they are registered on the client
machine. However, so are the SQLDMO objects, and they fail to work using
this method.
See the code below. Anyone have any ideas for me?
Thanks,
Rob
--
Public Function CreateObjectRemoteByCLSID(ByVal strCLSID As String, ByVal
strServerName As String) As Object
' NOTE: Can be used even if the CLSID specified is NOT installed on
client machine.
Const PROC_NAME = MODULE_NAME & ".CreateObjectRemoteByCLSID"
Const RPC_S_OK As Long = 0
Dim server() As Byte
Dim QI As MULTI_QI
Dim SS As SERVER_STRUCTURE
Dim refiid(16) As Byte
Dim lngReturn As Long
Dim CLSID As UUID
' ensure that leading and trailing {} are dropped
If Right$(strCLSID, 1) = "}" Then strCLSID = Left$(strCLSID,
Len(strCLSID) - 1)
If Left$(strCLSID, 1) = "{" Then strCLSID = Mid$(strCLSID, 2)
' build UUID structure from CLSID
lngReturn = UuidFromString(strCLSID, CLSID)
If lngReturn <> RPC_S_OK Then
Err.Raise -1, PROC_NAME, "Invalid CLSID: " & strCLSID
End If
' setup variables for CoCreateInstanceEx; initialize OLE
GetIIDforIDispatch refiid() 'set an IID for IDispatch
QI.pIID = VarPtr(refiid(0)) 'point to the IID
server = strServerName & Chr$(0) 'specify the server
OleInitialize 0 'initialise OLE
' point to server name and
' invoke a remote instance of the desired object
SS.pServer = VarPtr(server(0))
lngReturn = CoCreateInstanceEx(CLSID, 0, 16, SS, 1, QI)
If lngReturn <> 0 Then
Err.Raise lngReturn, PROC_NAME, "CoCreateInstanceEx returned error
code " & Hex$(lngReturn)
End If
' pass back object reference
Set CreateObjectRemoteByCLSID = QI.pInterface
End Function
|
|
|
|
|
I am developing an application which confirms to COM specifications in VC++ 6.0 using ATL COM. Some times I need to pass nearly more than 100 variable values across components, for which I need to provide Set / Get functions to set the get the same, which is tedious.
In order to avoid writing 200 functions, I have a thought of creating a structure or class with those variable and sending the object of this structure/class across components.
Could you please help me to accomplish the same?
(with some sample code )
Thanking you ...
Shesh
|
|
|
|
|
Are these variables are of the same type? You could send an array (look up size_is() and length_is() in IDL). You may want to consider using an enumerator.
|
|
|
|
|
Hi Shesh,
If the variables fits logically into a structure, you can create a COM object/interface to encapsulate the contents of this structure. Then just pass the disp interface of the structure across. This is the most generic way to do this, and will allow all types of clients (including scripting cilents) access to the contents of the struct. When you get the disp interface on the other side, just QI for the specific interface. Add the fields in the struct as read/write properties on the COM object representing the structure. This will still conform to the oleautomation attribute if you are using dual interfaces.
The interface for the object that contains the struct could look something like:
[
object,
uuid(D867979C-B209-41CD-9EA9-2455B98C64F1),
dual,
helpstring("IMyObject Interface"),
pointer_default(unique)
]
interface IMyObject : IDispatch
{
[id(1), helpstring("method GetData")] HRESULT GetData([out, retval] LPDISPATCH* pVal);
};
While the interface for the struct might look like:
[
object,
uuid(979D94E5-A586-452D-855D-0CE997BCC0AC),
dual,
helpstring("IDataStruct Interface"),
pointer_default(unique)
]
interface IDataStruct : IDispatch
{
[propget, id(1), helpstring("property Field1")] HRESULT Field1([out, retval] double *pVal);
[propput, id(1), helpstring("property Field1")] HRESULT Field1([in] double newVal);
[propget, id(2), helpstring("property Field2")] HRESULT Field2([out, retval] double *pVal);
[propput, id(2), helpstring("property Field2")] HRESULT Field2([in] double newVal);
};
In general, you can pass "objects" around in a dispatch friendly way by passing their dispatch interfaces, then dispatch clients will be able to use them. C++ clients can QI for the most specific interface (in this case, IDataStruct).
If you are not exposing dual interfaces on your COM object, you may want to have a look at the MIDL struct declaration. This would only be useful if you are using custom interfaces and did not have to worry about satisfying the oleautomation attribute.
I think there are a lot of other approaches to this as well, but I've had success with this one.
|
|
|
|
|
Hi,
I might look a bit selfish here, but,
have you tried this ?
www.codeproject.com\atl\udtdemo.asp
Hope this helps
|
|
|
|
|
I have had problem with registering COM components on clean winNT (sp 6) systems. Now it seems that the c++ runtime libraries on a clean system are older than on a system with WinNT & visual studio 6 (sp 4). Is there any way (application/source) that can check for MISSING dependencies of a COM component (exe & dll)?
regards,
Brian.
|
|
|
|
|
Hi,
Would you tell me How to send variant data type to Invoke method of a IDispatch interface through "named argument"?
I am doing Excel automation in C++. I got the pointer to Worksheet IDispatch interface. From this interface I want to get the pointer to Range IDispatch interface. The Range method in Worksheet IDispatch interface with take the cell position (eg. A1, A2) as in parameter of type VARIANT.
I need the information of how to send this argument to Invoke method of Range IDispatch interface.
regards,
Shiva
|
|
|
|
|