|
Thanks!
Here is the C++ code:
::CoInitialize(NULL);
ITestPtr ptrTest;
HRESULT hr = ptrTest.CreateInstance(CLSID_CTest);
BSTR text(L"Text");
::SysAllocString(text); // <-- I tried with and without allocating string.
hr = ptrTest->printme(text);
::CoUninitialize();
Thanks again!
|
|
|
|
|
BSTR text = SysAllocString(L"Text");
hr = ptrTest->primetime(text);
SysFreeString(text);
ptrTest->Release();
|
|
|
|
|
Hey
first of all Thanks!
I found the problem, I just had to use _bstr_t instead of BSTR! pretty weird eh...?
Thanks again!
|
|
|
|
|
Hi,
I have a Excel macro.
I have an array with values (example)
Human
Animal
Cooldrink
Telephone
I have any input parameter of "Animal 3". It loops through the array to search for a match, for example, if it checks the following:
Animal 3 = Animal, then it must bring back true.
It must just search for a partial value. How do I do this?
Thanks
Brendan
|
|
|
|
|
1.I call C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE using COM (OLE) of Visual C++.
2.I succeeded in call all the related _Application, _Workbook, Workbooks, Worksheets, _Worksheet, Range.
3.The problem I had is I search everywhere to find out the functions define (How to use) in all the related header files.
4.Below is an instance what I need.
This is the CAPPLICATION.h files, where I could possibly find out all the related definitions documentation?
// Machine generated IDispatch wrapper class(es) created with Add Class from Typelib Wizard
// CApplication wrapper class
class CApplication : public COleDispatchDriver
{
public:
CApplication(){} // Calls COleDispatchDriver default constructor
CApplication(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
CApplication(const CApplication& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}
// Attributes
public:
// Operations
public:
// _Application methods
public:
LPDISPATCH get_Application()
{
LPDISPATCH result;
InvokeHelper(0x94, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
long get_Creator()
{
long result;
InvokeHelper(0x95, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
return result;
}
LPDISPATCH get_Parent()
{
LPDISPATCH result;
InvokeHelper(0x96, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
LPDISPATCH get_ActiveCell()
{
LPDISPATCH result;
InvokeHelper(0x131, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
LPDISPATCH get_ActiveChart()
{
LPDISPATCH result;
InvokeHelper(0xb7, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
LPDISPATCH get_ActiveDialog()
{
LPDISPATCH result;
InvokeHelper(0x32f, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
LPDISPATCH get_ActiveMenuBar()
{
LPDISPATCH result;
InvokeHelper(0x2f6, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
CString get_ActivePrinter()
{
CString result;
InvokeHelper(0x132, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
return result;
}
|
|
|
|
|
Hi, i want to use an activeX (component, control, i don't know which) to control an device, and send some data to perform a standard web login (ok ok a little unstandard).
the device is a biometrical reader (yes, you put your finger on ), i had read some documentation about, but i have a lots of questions yet...
questions like:
- Can i develop an average activeX object, using the visual studio c++ express (without the MFC, ATL, etc..)??
- Is possible install that features on my version of visual studio (express)??
- Can i access to my device from the activeX object....
Sorry, if my questions seems so newbies : )... but i really appreciate your help
|
|
|
|
|
Hi, my IT department have doubts if the COM components in production environment really correspond to the source code in the visual source safe. It's the hard truth.
So...I'm searching for methods to verify is the source code is valid.
Just recompiling the source and compare the generated DLL with the DLL in production environment is not a valid way. As I have seen, even on sequential compilations the generated DLLs (with binary compatibility) are different, and not only on some bytes (like timestamps) as I thought.
I'm also thinking about building a tool to extract the typelibraries to compare them, it's not the final comparison but can help in cases the interface is different.
Any ideas ? A comparison tool telling Yes or No (the two COM DLLs are the same or not) would be my dream
EDIT: the source code is VB6.
Thanks for any help.
modified on Tuesday, April 8, 2008 2:08 PM
|
|
|
|
|
someome can tell me the way, thanks.
|
|
|
|
|
Hi in my project i want add VC++ dlls to the asp.net application. While i adding i have the following error
"A reference 'C:\Windows\System32\JQLiteServer.dll' could not be added"
JQLiteServer.dll is developed by VC++6.0
The dll contains 5 methods. I want call these methods in my asp.net appln.
anybody help me please...
Thanks in Advance
Prabakaran.
|
|
|
|
|
I'm learning ATL so i tried to write a simple project supporting connection points.
I want to have a situation that one COM client can raise an event on other clients.
1) I've created new ATL Project. I selected 'Executable' and 'allow merging proxy/stub' options
2) I've added an ATL Simple Object with 'support Connection Points' option. I named it 'Test'
3) I've added a method
[id(1), helpstring("method InsertText")] HRESULT InsertText([in] BSTR txt);
to the ITest interface
4) I've addedn a method
[id(1), helpstring("method OnTextInserted")] HRESULT OnTextInserted([in] BSTR txt);
to the ITestEvents interface
5) I've regenerated CProxy_ITestEvents
6) I've implemented InsertText method
<br />
STDMETHODIMP CTest::InsertText(BSTR txt)<br />
{<br />
this->Fire_OnTextInserted (txt) ;<br />
<br />
return S_OK;<br />
}<br />
7) I've added DECLARE_CLASSFACTORY_SINGLETON(CTest) to CTest
8) I've built the project
Next i wanted to test it so i've created a WindowsForms C# Application. I've added reference to my Test component. I've put a textbox and a button on it and implemented the button click to call InsertText method with textboxvalue as a parameter.
i've created also a secon application with a listbox:
<br />
private testLib.TestClass a;<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
a = new testLib.TestClass();<br />
a.OnTextInserted += new testLib._ITestEvents_OnTextInsertedEventHandler(this.Dn);<br />
}<br />
<br />
private void Dn(string b)<br />
{<br />
listBox1.Items.Add(b);<br />
}<br />
<br />
I think that clicking button in first application should add items to the listbox in the second application but it doesnt work.
Moreover, I've added to the second application a button calling InsertText method so when clicking this button an event should by both raised and handled by the same client. But it still doesnt work.
And now something strange. When i start 3 or more instances of the second application (in modified form) it starts to work! Event is properly handled after the button is clicked!
What am I doing wrong? Thanks in advance for your help.
modified on Thursday, April 3, 2008 7:08 AM
|
|
|
|
|
Hi
I want to send some data from a C# application to a COM dll written in C++. I'm not able to figure out how to set this up. I'm a beginner on both C# and C++.
I'm trying to create a .NET library (C#) containg an event and then import this dll to the C++ app (COM dll) with #import "...\filename.tlb" ... Then I'm using CoCreateInstance and so on to instanciate this.
Does anyone know of a good and simple example that shows how to set this up with a C# application, a .NET library and a COM dll (C++)?
Maybe this is totally wrong method to solve my problem. You may have any other good solutions to this.
I have looked at several articles on the Net, but haven't found the "right" one yet...
I appreciate very much your help here.
Steinar
|
|
|
|
|
God dag Steinar,
Velkommen å codeproject! Jeg overveie ikke noen svaret din spørsmål! Hvor er livet inne Egersund?
-David Delaune
|
|
|
|
|
Hi,
Here is the code of one of method of my COM object.
STDMETHODIMP Cmytestobj::FindWindowExWrapper(HWND hwndParent, HWND hwndChildAfter, LPCTSTR lpszClass, LPCTSTR lpszWindow, HWND* hwndRetWnd)<br />
{<br />
AFX_MANAGE_STATE(AfxGetStaticModuleState());<br />
<br />
HWND hRetFndWnd;<br />
*hwndRetWnd = FindWindowEx(hwndParent, hwndChildAfter, lpszClass, lpszWindow);<br />
return S_OK;<br />
}
First Question;
Is my code correct i.e. will it going to return wnd return by FindWindowEx.
Second Question:
I have generated an interop of that COM DLL and want to use that in my C# project, can anyone please tell me how can I use that in my C# project.
I have added the reference of interop in my project and able to create object of class Cmytestobj, but don’t know how to call that method, what should I replace for “HWND and LPCTSTR” data type in C# project.
Regards,
Mushq
|
|
|
|
|
Hello,
Using the below code, i am trying to authorize user "Valid\User1" to create COM object of "TestServiceSecurity" from a remote machine.
This code is working fine that is it not throwing any kind of error but still it is not giving autorization to "User1".
Can anybody help me with this?
Thanks in advance.
*************************************************************************************************************************
BOOL bDaclPresent = FALSE;
BOOL bDaclDefaulted = FALSE;
DWORD dwError = 0;
DWORD dwSize = 0;
EXPLICIT_ACCESS ea;
PACL pacl = NULL;
PACL pNewAcl = NULL;
PSECURITY_DESCRIPTOR psd;
SC_HANDLE schManager = NULL;
SC_HANDLE schService = NULL;
SECURITY_DESCRIPTOR sd = {0};
SERVICE_STATUS_PROCESS ssp;
DWORD dwBytesNeeded;
PSID sid;
schManager = OpenSCManager(0, 0, SC_MANAGER_CONNECT);
if (schManager == NULL)
DisplayError(GetLastError(), TEXT("OpenSCManager"));
schService = OpenService(schManager , "TestServiceSecurity",SC_MANAGER_ALL_ACCESS);
if (schService == NULL)
DisplayError(GetLastError(), TEXT("OpenService"));
psd = (PSECURITY_DESCRIPTOR)HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, dwSize);
// Get the current security descriptor.
BOOL bResult = QueryServiceObjectSecurity(schService, DACL_SECURITY_INFORMATION, psd, 0, &dwSize);
if (!bResult)
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER){
psd = (PSECURITY_DESCRIPTOR)HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, dwSize);
if (psd == NULL){
DisplayError(0, TEXT("HeapAlloc"));
// note HeapAlloc does not support GetLastError()
}
bResult = QueryServiceObjectSecurity(schService, DACL_SECURITY_INFORMATION, psd, dwSize, &dwSize);
if(!bResult)
DisplayError(GetLastError(), TEXT("QueryServiceObjectSecurity"));
}
else
DisplayError(GetLastError(), TEXT("QueryServiceObjectSecurity"));
}
// Get the DACL.
bResult = GetSecurityDescriptorDacl(psd, &bDaclPresent, &pacl, &bDaclDefaulted);
if (!bResult)
DisplayError(GetLastError(), TEXT("GetSecurityDescriptorDacl"));
// Build the ACE.
BuildExplicitAccessWithName(&ea, TEXT("Valid\\User1"), COM_RIGHTS_EXECUTE,
SET_ACCESS, NO_INHERITANCE);
dwError = SetEntriesInAcl(1, &ea, pacl, &pNewAcl);
if (dwError != ERROR_SUCCESS)
DisplayError(dwError, TEXT("SetEntriesInAcl"));
//AddAccessAllowedACEToACL(
bool bIsValidACL = IsValidAcl(pacl);
// Initialize a NEW Security Descriptor.
bResult = InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
if (!bResult)
DisplayError(GetLastError(), TEXT("InitializeSecurityDescriptor"));
// Set the new DACL in the Security Descriptor.
bResult = SetSecurityDescriptorDacl(&sd, TRUE, /*pNewAcl*/NULL, FALSE);
if (!bResult)
DisplayError(GetLastError(), TEXT("SetSecurityDescriptorDacl"));
// Set the new DACL for the service object.
bResult = SetServiceObjectSecurity(schService, DACL_SECURITY_INFORMATION, &sd);
if (!bResult)
DisplayError(GetLastError(), TEXT("SetServiceObjectSecurity"));
// Close the handles.
bResult = CloseServiceHandle(schManager);
if (!bResult)
DisplayError(GetLastError(), TEXT("CloseServiceHandle"));
bResult = CloseServiceHandle(schService);
if (!bResult)
DisplayError(GetLastError(), TEXT("CloseServiceHandle"));
// Free buffers.
LocalFree((HLOCAL)pNewAcl);
HeapFree(GetProcessHeap(), 0, (LPVOID)psd);
*************************************************************************************************************************
|
|
|
|
|
Hi,
I am using
SetWindowPos(&wndTopMost,0,0,0,0,SWP_NOSIZE);
inside OnInitDialog() to place the dialog as the top most.But after that if i click on any other opened application this window is not getting minimized on to the taskbar.
This dialog is displayed through a com interface.
Please help,it is urgent.
|
|
|
|
|
Although a very basic question, but can anybody tell me what COM uses internally to talk between components? Is the mode of communication same for COM and DCOM or are they different? Do they use RPC, Sockets, Pipes, etc...?
Thanks.
---
Hakuna-Matata
It means no worries for the rest of your days...
It's our problem free, Philosophy
"I think my response was 'What idiot dreamed this up?'" -- Mary Ann Davidson, Oracle's chief security officer, in typical blunt manner, remembering her reaction to the company's scheme to brand its databases as "unbreakable."
|
|
|
|
|
If calling between code in the same process, in the same context, in the same apartment, there is no translation whatever. It's the same as making a virtual function call to another class in your own code.
If in a different COM+ context in the same apartment, it marshals the arguments to make any pointers context-relative, executes any code to set up the thread for the new context, and unmarshals arguments and calls the method. On return it again sets up the thread for the right context, remaps any pointers for the right context (to ensure correct interception occurs) and returns to the caller.
If in a different apartment, it depends on the receiving apartment. If the receiving apartment is an STA, it will have created a hidden window to receive incoming calls. The arguments are marshalled and a window message sent to that hidden window. When the receiving thread's message pump picks up the message and dispatches it to the window procedure, the window procedure makes the call. The calling thread waits (pumping messages, if an STA) until the call returns.
If the receiving apartment is an MTA, it uses RPC, but a special RPC channel called Local RPC, to get the call onto a worker thread.
If going cross-process, again it uses windows messaging to target an STA, and RPC to target an MTA.
For DCOM RPC is always used.
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
|
Hi
Can you please tell me...what is the wrong in the following code snippet .
BSTR abc;
abc is having some data in it.
Now I need to check whether abc is having empty string.
for that I wrote the code like this
if( abc ==L"")
AfxMessageBox("empty string");
But I receive a compilation error ;
Please help me to ressolve the issue.
Thanks in advance.
|
|
|
|
|
Use SysStringLen[^] for BSTR
BSTR is not a class. If you wish to use == for comparing two BSTRs then use _bstr_t class which wraps BSTR data type
Sohail
modified 21-Apr-21 21:01pm.
|
|
|
|
|
you may use
if ( wcscmp(abc,L"") == 0)
AfxMessageBox("empty string");
or, if you want to use the equality operator, choose to encapsulate the BSTR data inside a _bstr_t object.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Hi
I am creating dll using C#. I made the research and little bit confused with following:
1) does all the classes need Guid?
2) Does all the class need interface classes? or can I have just regular class without interface and Guid?
[Guid("....")]
public interface myclass_interface
{
....
}
[Guid("...."),
ClassInterface(ClassInterfaceType.None)]
public class myclass_class:myclass_interface
{
..
}
3) Can library have static function/procedures so other classes can call them directly?
4) Can I have a class, that will not be calling from COM client, without a guid?
Thank you.
|
|
|
|
|
pnpfriend wrote: ) does all the classes need Guid?
No. This is only needed if you are going to access the class from COM.
pnpfriend wrote: 2) Does all the class need interface classes? or can I have just regular class without interface and Guid?
No, classes are not required to implement an interface. Interface essentially allow you to define the "contract" that the class will provide. It does nothing to ensure how that contract is implemented but only that specific methods/properties will be available.
pnpfriend wrote: Can library have static function/procedures so other classes can call them directly?
The library can't, but an individual class can have static methods and/or properties that can be called without requiring an instance of that class.
pnpfriend wrote: Can I have a class, that will not be calling from COM client, without a guid?
This is pretty much the same as question 1, just asked inversely...so yes, you can have a class that isn't called from COM without a GUID.
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
I am trying to work out a simple COM/.NET interop code. In my project in VB, I have created a simple windows application to add two numbers. The functionality of adding is done through the help of a .NET DLL written in C#. I am quite confused by trying various ideas sugggested by people. Can anyone clarify this simply in a step by step fashion?
This my VB code:
Private Declare Function method Lib "C:\Documents and Settings\CSfiles\interop\interop\bin\Debug\interop.dll" Alias "interopdll" (ByVal X As Integer, ByVal X As Integer)
Private Sub Command1_Click()
Dim a As Integer
Dim obj As Object
obj = New sample ' I get a compile-time error for undefined user type here.
a = obj.method(CInt(Text1.Text), CInt(Text2.Text))
Label1.Caption = CStr(a)
End Sub
My C#(.NET DLL) Code:
using System;
using System.Runtime.InteropServices;
using System.Reflection;
[assembly: ComVisible(true)]
namespace interop
{
/// <summary>
/// Summary description for Class1.
/// </summary>
[ClassInterface(ClassInterfaceType.AutoDual)]
[GuidAttribute("6CE9C732-CD90-4042-A5F0-CF71DFAC2598")]
class sample
{
public sample()
{
}
public int c;
public void method(int a, int b)
{
c = a+b;
//return c;
}
}
}
In this I have registerd the DLL with /codebase switch while using regasm.exe too.
Regards,
Lenus.
modified on Monday, March 24, 2008 3:49 AM
|
|
|
|
|
Statement "Private Declare Function method Lib..." is unwanted and should be removed.
I.1. Add typelib into VB project by menu "Project" -> "References...". Search your DLL or TLB there (something like "interop") and select it.
I.2. Create new instance with New and Set operator
Dim obj As sample
Set obj = New sample
II. Create new instance with CreateObject and Set operator
Dim obj As Object
Set obj = CreateObject("interop.sample")
With best wishes,
Vita
|
|
|
|
|