|
AFAIK, to close Excel application you have to create it via CoCreateInstance
|
|
|
|
|
I want to use an interface method in my com class . Now this can be archive by two ways
1) by importing tlb file in idl file.
ii) by including/adding .h file.
Can you please explain the diff betn approach i and ii and in which scenario we should use them?
|
|
|
|
|
Reading from my COM IDL & Interface Design by Al Major (Wrox):
#include
The contents of the #included file are placed in the idl as if they had been typed in.
import
Is the standard method for bringing in definitions from other idl, odl or C/C++ header files into the main IDL file
Al recommends: not using #include unless you need to support legacy types and using: import to get at IDL declarations.
|
|
|
|
|
Importing using #import can be used to instantiate a COM component from its type library that is either embedded inside the DLL or as a separate file (.TLB file).
This method prompts the compiler to create the header files which is automatically included in the generated source codes.
It also create smart pointer for all the exposed interfaces using the _com_ptr_t class. The smart pointers will have a naming convention of xxxPtr where xxx is the name of the exposed interface.
The method of #include is a more basic approach where you use the standard COM APIs like CoCreateInstance to instantiate and use the COM component. You will have to manually create smart pointers if needed.
|
|
|
|
|
Good Morning,
I need to call a dll from C# that was generated by magic edeveloper. I think it is a C dll.
It is a program that takes in 3 parameters all integers. Adds the first to and pass the sum to the 3rd parameter.
I have registered the dll in windows and I can add a reference in visual studio via the Project Add Reference menu.
I have the following code in my project
int a = 5;
int b = 6;
int sum = 0;
double sumDouble = 0;
sumdll.sumdllClass sdc = new sumdll.sumdllClass();
sumDouble = sdc2.sumdll(ref a, ref b, ref sum);
But if I run it I get the error
Unable to cast COM object of type 'sumdll.sumdllClass' to interface type 'sumdll.Dsumdll'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3DC9FCBA-9E72-49AA-B597-F9B2603D5EEA}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
the following is available from the intellisense
sumdll.sumdllClass sdc = new sumdll.
Dsumdll which is an interface
Sumdll which is an interface
sumdllClas which is a class
And in the line
sumDouble = sdc2.sumdll(
ref int input1, ref int input2, ref @input)
Does anyone know I am getting this error? Or how to call the dll correctly.
Regards,
Christiaan Pieters
|
|
|
|
|
Ok so I tried to do the same thing in VB.NET. I usally work in a console application for ease and once I have succeded I will convert or redo what every I have to do.
The console application in VB.NET is by default in a module.
If I do the following in VB.NET from the module
Console.WriteLine("Start")
Dim dllRef As New sumdll.sumdll()
Dim a As Integer = 10
Dim b As Integer = 18
Dim c As Integer = 0
Dim d As Double = 0.0
d = dllRef.sumdll(a, b, c)
Console.WriteLine("Done")
Console.WriteLine(a)
Console.WriteLine(b)
Console.WriteLine(c)
Console.WriteLine(d)
Console.Read()
But if I move the same code to a class I still get the same error as before. Why can’t this be called from a class? If I can get this to run from a class I am sure I will be able to call this from C#.
Thanks,
Christiaan
|
|
|
|
|
I can only give you the advice to use better names for your stuff. You are mixing interfaces and classes.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Well.. Do you try to register this dll in to the GAC?
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
I'd like to use Registration-Free Activation of .NET-Based Components to make my application side by side.
http://msdn.microsoft.com/en-us/library/ms973915.aspx#rfanetwalk_topic4
From this article, I can't get an idea to slove my issue.
Here is the calling logic in my application. I have a dll(done by delphi) to invoke a .NET COM, but the dll will be loaded in a .NET application. I tried to add a manifest with the executable file name, but always failed to load the .NET COM. (.NET Application <- Delphi DLL <- .NET COM)
I tried a Delphi application to load the .NET COM with manifest file and it is ok. Is it possible to attach the manifest inforamtion to a DLL????
can anyone help?
thanks in advance.
|
|
|
|
|
Hi All,
I have created COM component(dll) and created one client to use it, Please finnd the code of client:-
HRESULT hr = CoInitialize(0);
Please give me some solutions coz i tried every possible way.
Thanks A Ton
Ash_VCPP
walking over water is just knowing where the stones are.....
|
|
|
|
|
your code isnt readable.
What are the error codes? Google them
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Hi KarstenK,
I am getting value of hresult= -2147221164
Please find the code below:
HRESULT hr = CoInitialize(0);
//CoCreateInstance(
SCRIPTOBJLib::IScriptObjPtr sobj;
//sobj->QueryInterface(IId_,void* &vp);
//HRESULT hRes = CComObject<CScriptObj>::CreateInstance(&sobj);
//CreateInstance(NULL,IID_IUnknown,(void*)&vp);
HRESULT hres = sobj.CreateInstance ( __uuidof(SCRIPTOBJLib::IScriptObj) );
//HRESULT hres = sobj.CreateInstance("ScriptObj 1.0 Type Library");
sobj->SetLanguage((unsigned short *)"VBScript");
CoUninitialize();
Thanks A Ton
Ash_VCPP
walking over water is just knowing where the stones are.....
|
|
|
|
|
I think that the issue is that you are using getting the ID of the interface:
__uuidof(SCRIPTOBJLib::IScriptObj)
You need the ID of the coclass in the CreateInstance call. It is probably __uuidof(SCRIPTOBJLib::ScriptObj) depending on how the object has been implemented.
|
|
|
|
|
But from the library i am getting two things:
1.IScriptObj
2.IScriptObjptr
So what else i can try.
Thanks A Ton
Ash_VCPP
walking over water is just knowing where the stones are.....
|
|
|
|
|
Please use for HRESULT hexadecimal values (Just do it! if you want to run COM)
if you google that (-2147221164 => hex 80040154) you find things like "class not registered". This means that SCRIPTOBJLib::IScriptObj isnt registered properly. ->regsvr32
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
I note the poster has two threads going on this question, one here and one in the C++ forum. I have now bowed out.
|
|
|
|
|
Hi All,
While building the COM DLL i am getting these three linking errors:-
1. error LNK2001: unresolved external symbol "public: virtual long __stdcall CScriptObject::QueryInterface(struct _GUID const &,void * *)" (?QueryInterface@CScriptObject@@UAGJABU_GUID@@PAPAX@Z) ScriptObject.obj
2. error LNK2001: unresolved external symbol "public: virtual unsigned long __stdcall CScriptObject::AddRef(void)" (?AddRef@CScriptObject@@UAGKXZ)ScriptObject.obj
3.error LNK2001: unresolved external symbol "public: virtual unsigned long __stdcall CScriptObject::Release(void)" (?Release@CScriptObject@@UAGKXZ)ScriptObject.obj
Please provide me some suggestions.
Thanks A Ton
Ash_VCPP
walking over water is just knowing where the stones are.....
|
|
|
|
|
Probably, You didn't implement this methods.
|
|
|
|
|
Need help on reading and writing XML in COM with VC++
i need to read XML file and implement algorithem and then update the XML file
|
|
|
|
|
Look at MSXML[^]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
I'm using IPPort from nsoftware (IP*works) to implement a socket server
and I want to Insert de data received from client in OnDataIn event.
How should I implement the Oracle Connection and insert command?
Here is the code Example of Socket Server:
namespace nsoftware.Demos
{
public class echoserverDemo : System.Windows.Forms.Form
{
internal System.Windows.Forms.Label lNotice;
internal System.Windows.Forms.TextBox tbPort;
internal System.Windows.Forms.Label lPort;
internal System.Windows.Forms.Button bRun;
internal System.Windows.Forms.TextBox tbLog;
private nsoftware.IPWorks.Ipdaemon ipdaemon1;
internal TextBox tbMessage;
internal Label label1;
internal Button bSend;
private IContainer components;
public echoserverDemo()
{
InitializeComponent();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
STAThread
static void Main()
{
Application.Run(new echoserverDemo());
}
private void bRun_Click(object sender, System.EventArgs e)
{
if (bRun.Text == "Start")
{
ipdaemon1.LocalPort = Convert.ToInt32(tbPort.Text);
ipdaemon1.InvokeThrough = this;
ipdaemon1.Listening = true;
bRun.Text = "Stop";
tbLog.AppendText("Starting server.\r\n");
}
else
{
ipdaemon1.Listening = false;
//to disconnect all clients:
ipdaemon1.Shutdown();
bRun.Text = "Start";
tbLog.AppendText("Stopping server.\r\n");
}
}
private void ipdaemon1_OnConnected(object sender, nsoftware.IPWorks.IpdaemonConnectedEventArgs e)
{
ipdaemon1.Connections[e.ConnectionId].AcceptData = true;
tbLog.AppendText(ipdaemon1.Connections[e.ConnectionId].RemoteHost + " has connected.\r\n");
ipdaemon1.Connections[e.ConnectionId].EOL = "\r\n";
}
private void ipdaemon1_OnDataIn(object sender, nsoftware.IPWorks.IpdaemonDataInEventArgs e)
{
tbLog.AppendText(ipdaemon1.Connections[e.ConnectionId].RemoteHost + " - Echo '" + e.Text + "'.\r\n");
ipdaemon1.Connections[e.ConnectionId].DataToSend = e.Text;
}
private void ipdaemon1_OnDisconnected(object sender, nsoftware.IPWorks.IpdaemonDisconnectedEventArgs e)
{
tbLog.AppendText("Disconnected " + e.Description + " from " + e.ConnectionId + ".\r\n");
}
private void bSend_Click(object sender, EventArgs e)
{
foreach (Connection conn in ipdaemon1.Connections.Values)
{
conn.DataToSend = tbMessage.Text;
}
}
|
|
|
|
|
Hi Friends,
I am sorry if it not the right forum for posting outlook 2007 automation problems.
Here is my problem :
I want to add two buttons on the General Section of the Dialog that pops up ,when you click on the name of a contact (from address book).That is when you want to see more details of the person,who sent you the mail , you normally double click on the name of the person. If the person contact is already existing in your contact list a Properties dialog with sections General, Phone\Fax, Company , E-mail Addresses pops up. I want to modify the General section by adding two buttons.
I did not find any information on net, related to this.
Please let me know,how to go about this ?
Thanks
Appu..
"Never explain yourself to anyone.
Because the person who likes you does n't need it.
And the person who dislikes you won't believe it."
|
|
|
|
|
I doubt that this is possible.
What are you trying to achieve with the 2 buttons?
|
|
|
|
|
i am stuck with one kind of problem when using COM . below are the details ,
i have written a class which has a com object as a member variable. i have different member function one will create the com object other members will access the functions of the com object. the problem comes when i am trying to access function of the com .
here is sample example of my code
class CMyclass
{
com variable;
public:
void createcomobject();
void accessfunctionofcomobject();
};
CMyclass::void createcomobject()
{
::CoInitialize()
CoCreateInstance(......);
// Every this is fine and i was able to create the com object successuflly ..
// every thing is fine and successfull.
// successfull creates com object using cocreateinstance.. and we can call the memebers function of interface
variable->method(); // successfully calls the members
}
CMYclass::accessfunctionofcomobject()
{
// application crashes when try to access com object functions
variable->method(); // UNHANDLED EXPECTION
}
CMYclass *ptr; // This is gobal pointer variable..
// fun1 is a gobal function
void fun1()
{
ptr->createcomobject();
}
// fun2 is a gobal function
void fun2()
{
ptr->obj.accessfunctionofcomobject(); //calling this funciton makes crash.
}
void main()
{
ptr = new CMYclass();
fun1(); // This function calls creates successful com object inside a class object.
fun2(); // This function calls makes crash...
}
i want to know why the unhandled exception is raising
modified on Thursday, November 19, 2009 11:53 PM
|
|
|
|