|
Hi all,
I am new in ATL COM, I have created a Simple Object using ATL Object wizard,
and one simple Method.
The appwizard generated something like this
<br />
class ATL_NO_VTABLE CSimpleObject :
public CComObjectRootEx<CComSingleThreadModel>,<br />
public CComCoClass<CSimpleObject, &CLSID_SimpleObject>,<br />
public IDispatchImpl<ISimpleObject, &IID_ISimpleObject, &LIBID_FIRSTLib><br />
{<br />
}<br />
Now i am trying to use this component in client(mfc app), for that i have imported the header file of the component(simpleobject.h) in my mfc app.
When i try to compile my mfc app.
Its gives me
error C2079: 'CSimpleObject' uses undefined class 'ATL_NO_VTABLE
Can anybody tell what is error in ATL world??
Thanks in advance,
Abhi Lahare
|
|
|
|
|
It's a macro which expands to __declspec(novtable) for Visual C++. This is a hint to the compiler not to set the virtual function table pointer in the constructor. From the documentation:
"This form of __declspec can be applied to any class declaration, but should only be applied to pure interface classes, that is, classes that will never be instantiated on their own. The __declspec stops the compiler from generating code to initialize the vfptr in the constructor(s) and destructor of the class. In many cases, this removes the only references to the vtable that are associated with the class and, thus, the linker will remove it. Using this form of __declspec can result in a significant reduction in code size.
"If you attempt to instantiate a class marked with novtable and then access a class member, you will receive an access violation (AV)."
You don't normally use an ATL object derived from CComObjectRootEx directly; instead, the ATL class factory generates a CComObject<CSimpleObject> when it's asked to by COM. Eliminating the vtable can save on both code size (through not setting the vfptr) and on data size (through omitting CSimpleObject's vtable).
If you don't want to use CSimpleObject as a COM object, remove ATL_NO_VTABLE, all of the CComXxx base classes, and IDispatchImpl .
If instead you want to use the COM object from your MFC application (leaving the object implementation in the DLL), use ClassWizard or a #import statement to reference the type library. You could also use the interface headers generated from the IDL file that describes the object's interfaces. Use CoCreateInstance to create the object.
|
|
|
|
|
Hi Mike,
I want to do
MiKe:
If instead you want to use the COM object from your MFC application leaving the object implementation in the DLL), use ClassWizard or a #import statement to reference the type library. You could also use the interface headers generated from the IDL file that describes the object's interfaces. Use CoCreateInstance to create the object
but how??. (i.e how my client (mfc app) will know the defination of "CSimpleObject")
Again Thanks in Advance.,
Abhi Lahare
|
|
|
|
|
Actually i am developing a class in which it will take any com object and will be able to set and get the properties. Now i have taken the clsid of the component. Now how can i get its properties as GetIdsofNames function of IDispatch takes names. Please Guide me briefly with a little example or tell me some article
Thanx in advance
Regards
minamkhan
Inam
|
|
|
|
|
GetIDsOfNames accepts property names too, but I think you want to know the names of supported properties instead. You need to read the object's type information.
You can ask an object if it can provide type information by calling the GetTypeInfo method of IDispatch . You can then find out how many properties it has by calling ITypeInfo::GetTypeAttr . You can get information on the properties with ITypeInfo::GetVarDesc .
|
|
|
|
|
Sir Actually i have only the progId of the component now i want to also know how i will get the interfaces in this component dynamically than how can i get the names and return types of the properties in the interface dynamically. so that i will be able to get and set the properties in that interface. Sir please explain me little briefly as i am new to this topic. or if possible gave me a little example too.
Thanx in advance
Regards
minamkhan
Inam
|
|
|
|
|
Does anyone know of a "commercial" ActiveX control that utilizes a CListCtrl/CListView?
Charlie Roderick
|
|
|
|
|
Hmm.. what do you mean with utilizes? Are you looking for an activex control which behaves just like CListCtrl, or are you just curious whether anyone have been "bold enough" to use CListCtrl commercially?
--
Gott weiß ich will kein Engel sein.
|
|
|
|
|
Either and/or both.
Charlie Roderick
|
|
|
|
|
I'm trying to get a file path from a pointer to a PIDL.
This is using the following function:
BOOL SHGetPathFromIDList(
LPCITEMIDLIST pidl,
LPTSTR pszPath
);
where pidl is an IntPtr to a pidl pulled from the SHBrowseForFolder.
I am using the following lines of code to call it:
<br />
IntPtr pidl = SHBrowseForFolder(lpbi);<br />
string filePath = new string(' ', 200);<br />
SHGetPathFromIDList(pidl,out filePath);<br />
via the wrapped method:
<br />
[DllImport("shell32.dll", CharSet=CharSet.Auto)]<br />
public static extern int SHGetPathFromIDList(<br />
IntPtr pidl,<br />
[Out, MarshalAs(UnmanagedType.BStr)]<br />
out string pszPath); <br />
The problem is that while pidl has a value, the method crashes when I try and interpret a file / folder greater than 1 depth.
And if it does not crash, I get the unmodified string returned to me.
Any ideas what I'm doing wrong?
Cheers
Cata
Edit: I suppose the question is - How do I construct a buffer of size Max_Path, and then create a pointer to it?
|
|
|
|
|
Solved it, no need to reply ^^
|
|
|
|
|
Use a StringBuilder . Note: wrong forum, please use the NET Framework forum for .NET questions.
|
|
|
|
|
I'm new to COM, so I am experimenting with some simple functions. I've had a degree of success with the SHBrowseForFolder function, in that I can open the dialog, setup the flags, rename it etc.
These are all parameters in the in/out structure struct_browseinfo.
The problem I have is, this inout structure is supposed to return a field pszDisplayName which contains the path of the folder right?
I've tried marshaling it as a number of different types of strings, and even an intptr (I am using C#), but it's always null, no matter what I do.
I'm using no owner for the dialog, no pidl root value, and the function still returns a folder index, But no string name.
Any idea why this is?
Cheers
Cata
|
|
|
|
|
I've looked into it a bit further, and the pszDisplayName is a pointer to a buffer of MAX_PATH charachters.
How would I go about marshaling this in C#?
I'm assuming that is what causes it to be a null value...
Any help appreciated.
Cheers
Cata
|
|
|
|
|
Ok, I've solved it using a pre initialised string. Thank you VS.NET for helpful error messages ^^
Anyway, Does this dialog box return the full path? Or am I stuck with only getting the folders name...
There has to be some way to fetch the full path... but i'll carry on looking at the tutorial now I have this solved.
Regards
Cata
|
|
|
|
|
Hello
Can I overload my COM object methods? I want to have two methods:
addMyObject(BSTR name);
addMyObject(BSTR name, BSTR address);
Can I do this? If not, is there a way of doing it or must I use different names for my methods?
|
|
|
|
|
No, use different names. Technically it's possible, but it's a nightmare. Using different names is easier.
From an "official" point of view, the names of the methods are irrelevant, unless it's IDispatch based, but it's sooo much easier with different names;
addMyObject(BSTR name);
addMyObjectWithAddress(BSTR name, BSTR address);
Remember, the IDL will produce a header file; it could be used in a C++ app, which supports overloading, or in a C app, which doesn't...
Steve S
|
|
|
|
|
Thank you
|
|
|
|
|
I want to paste in my app img. It pastes only from MS Word and IE.Can anyone help me? My app is a rtf app based on dialog box.
Tanks a lot.
|
|
|
|
|
Anyone who use VB will know it's esay to use ListView and ImageList in VB, however i want to use it in VC. I found that i cannot create ListImages object which is used by ImageList, i use the following codes:
I use import directive to import the com class
IImageListPtr imgs;
imgs.CreateInstance(__uuidof(ImageList));
IImagesPtr img;
img.CreateInstance(__uuidof(ListImages));
Can any one tell me what the problem is?
Thanks a lot!
I love C++
|
|
|
|
|
Hi all
I have a trouble in My ActiveX control
I have written a method that has a parameter as VARIANT pointer (VARIANT FAR* lpVarFileInfo)
in my application that use this ActiveX, i passs a struct : FILE_INFO (it's a struct), and in my ActiveX control i want to get all parameter of this struct, but it alway is wrong.
here my code
IN APPLICATION
FILE_INFO FileInfo;
FileInfo.FileName = _T("D:\\GUI");
m_EditorLoader.SetInfo((VARIANT*)&FileInfo);
// m_EditorLoader is an instance of ActiveX control
IN ACTIVEX CONTROL
void CEditorCtrl::SetInfo(VARIANT FAR* lpVarFileInfo)
{
FILE_INFO FileInfo;
FileInfo = *(FILE_INFO*)(lpVarFileInfo);
AfxMessageBox(FileInfo.FileName);
// Value is wrong
}
|
|
|
|
|
A variant per se cannot contain an arbitrary user-defined type. However, it can be a SAFEARRAY of VT_RECORD, providing the record type is assigned a GUID, and is defined somewhere in a type library.
You don't show the rest of your FILE_INFO structure, but if you only want a name, you could pass a BSTR, and if you must have other members, could you not pass OLE Automation compatible types as multiple parameters, rather than as a structure, to keep things 'simpler'...?
Steve S
|
|
|
|
|
ok, FILE_INFO struct is
typedef struct tagFILE_INFO
{
CString FileName;
CString Location;
CString LocationTemp;
}
FILE_INFO;
Because my ActiveX control communicate with an application. I need passing a lot of pararameters as struct.
could you give me example code.
regards
|
|
|
|
|
If you want your active X control to be useful to non-MFC programmers, then don't use CStrings!
In your IDL you can define your structure as you might in C++ (but with no member functions). Your types should be simple oleautomation compatible ones, so CStrings are out, because they can't be marshalled by OLEAUT32.
Steve S
|
|
|
|
|
ok, i have change CString to BSTR, but how can add a method in my ActiveX has parameters as FILE_INFO (example)
define FILE_INFO struct in odl file
typedef struct tagFILE_INFO
{
BSTR szFileName;
BSTR szLocation;
BSTR szLocationTemp;
}
FILE_INFO;
because my component is an ActiveX control so, in my odl file
[id(7)] void SetInfo(FILE_INFO FileInfo);
it will appear Error when you launch to class wizard (passer error). Because in ActiveX control,when you add one method. The parameter type alway has some
PREDEFINE TYPE (short, long ,CURRENTCY... VARIANT....
So how can we define a new type(UDT) for parameter in method.
Regards
TrungHuynh
|
|
|
|