Click here to Skip to main content
15,909,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am in the process of converting a VB Project to C#. Now I am getting problem with a Createobject function,which I couldn't understand exactly what it is.

VB
Set DVXRT = VBA.CreateObject("DVXR48OLE.CDVXRT")
If (DVXRT.Login(nFirma, sCode$, sPWT$, gsDBServer, sPath)) Then.....

Here DVXR48OLE.CDVXRT is an application done by some person.When the If condition enters, a login form is loaded. Login form is from the application.

What I have tried:

I tried this in C#
C#
<pre lang="c#"> Object obj = Activator.CreateInstance(Type.GetTypeFromProgID("DVXR48OLE.CDVXRT"));
If (obj.Login(nFirma, sCode$, sPWT$, gsDBServer, sPath)


Error comes that there is no Login in obj. The problem is no details about the application. If anyone have ideas please share me. It ll be so helpful
Posted
Updated 27-Feb-19 1:43am

"DVXR48OLE.CDVXRT" is a COM object that has to be registered on the machine. To use it from .net you need to use a proxy system called interop. Basically add a reference to the relevant COM object via the Add Reference dialog and Visual Studio will create a .net class you can use in your code which in turn uses the underlying COM object. Depending on what this object does there is no guarantee it'll work from your c# code.

Google ".net interop" or "calling com objects from c#" for more details\examples.
 
Share this answer
 
Follow the instruction from: How the new C# dynamic type can simplify access to a late bound COM object[^]

C#
Type custom = Type.GetTypeFromProgID("DVXR48OLE.CDVXRT");
//magic word: dynamic!
dynamic obj = Activator.CreateInstance(custom);
//late binding in action!
if (obj.Login(nFirma, sCode$, sPWT$, gsDBServer, sPath)
{
    //...
}
 
Share this answer
 
v2
Comments
Priya Karthish 27-Feb-19 8:16am    
Error : The name 'dynamic' does not exist in the current context. Do I need to add any reference for this?
Maciej Los 27-Feb-19 8:41am    
Priya Karthish 27-Feb-19 10:43am    
Now Error is gone. But I don't know the Login form is not opening. I just checked my VB project. I gave the exact same as in VB. But from VB the login form opens, but from C# it's not opening. Couldn't able to guess why?
Maciej Los 27-Feb-19 11:07am    
You should check if obj is not null first!
Priya Karthish 27-Feb-19 10:56am    
Is there any possible to check what is in the Login function of the COM object(DVXR48OLE.CDVXRT)?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900