|
Without creating a control ,can i provide activex scripting for my
mfc application.please refer the web sites so that i can learn from the
scratch...i need step by step learning with suitable examples
|
|
|
|
|
hi
is it possible to send a BSTR to a method expecting _bstr_t?
thank you?
|
|
|
|
|
Yes. _bstr_t is a c++ wrapper class for handling BSTR.
Please check the _bstr_t constructors documentation in MSDN.
Have a great day ahead!
Regards,
Sohail Kadiwala
(My Blog - http://blogs.wdevs.com/sohail/[^])
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Hello pardis,
Here's a simple example program to illustrate it :
#include <windows.h>
#include <comdef.h>
#include <iostream>
void Function01(_bstr_t bst)
{
std::cout << (char*)bst << "\r\n";
}
int main()
{
BSTR bstr01 = ::SysAllocString(L"Hello World.");
Function01(bstr01);
if (bstr01)
{
::SysFreeString(bstr01);
bstr01 = NULL;
}
return 0;
}
The BSTR defined in main() (i.e. bstr01) is treated by the compiler as a "const wchar_t*" when it enters Function01().
Next, the compiler will take the const wchar_t* and use it as the parameter to the version of the _bstr_t constructor that takes a "const wchar_t*". The resultant _bstr_t object is "bst".
The std::cout stuff is just to demonstrate a usage of the "bst" object.
Hope the above will be helpful,
Bio.
|
|
|
|
|
|
I need to develop an application that will export a DataGrid to Excel. But for compatibility reasons, it can't be anything later than Excel 2000. I have Office XP on my machine. I need to get hold of the Excel.dll version 9 (as far as I know that is the 2000 compatible one). I downloaded one from a sample article I found, but when I try to reference it in my project, I get an error that says 'Only assemblies with extension 'dll' and COM components can be referenced. Strange that, since it is a dll. Does anyone know where I can get hold of a legit version of this dll and how I can make it work. I searched on msdn.microsoft.com – to no avail. I'm also looking for a decent reference about the object's properties, methods etc.
Any help would be greatly appreciated.
|
|
|
|
|
Hello All,
I am trying to develop a VB6 application in which I have used spreadsheet component.Now I want to copy data from an external excel file to the spreadsheet component inside the form. What are the possible ways
|
|
|
|
|
i have developed a VC++ application hosting Dhtml Edit Control inside which i have placed ActiveX control.
Activex control are basically customized buttons in html page that i have loaded in Dhtml edit control.
I have successfuly captured Dhtml Events in VC++ when simple html page is loaded.
when i load the html page with the Activex control my visual applicaiton is unable to capture the events.
I want to capture ActiveX events which is hosted in Dhtml Edit Contol, in my VC++ applications.
BOOL CDOMGeneralSubs::EstablishConnectionPoint
(IDispatch * dom,IDispatch*pHTMLElementEventsHandler)
{
// AfxMessageBox( "in EstablishConnectionPoints" );
BOOL bRet=FALSE;
IConnectionPointContainer*pConnectionPointContainer;
HRESULT Result=dom->QueryInterface(IID_IConnectionPointContainer,(void**)&pConnectionPointContainer);
if(SUCCEEDED(Result))
{
IConnectionPoint*pConnectionPoint;
Result=pConnectionPointContainer->FindConnectionPoint(DIID_HTMLDocumentEvents,&pConnectionPoint);
if(SUCCEEDED(Result))
{
DWORD Cookie=0;
Result=pConnectionPoint->Advise(pHTMLElementEventsHandler,&Cookie);
if(SUCCEEDED(Result))
bRet=TRUE;
pConnectionPoint->Release();
}
pConnectionPointContainer->Release();
}
return bRet;
}
STDMETHODIMP XSZone::CHTMLElementEvents::Invoke(
DISPID dispIdMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS FAR* pDispParams,
VARIANT FAR* pVarResult,
EXCEPINFO FAR* pExcepInfo,
unsigned int FAR* puArgErr
)
{
// AfxMessageBox( "in Invoke" );
switch (dispIdMember)
{
case DISPID_HTMLELEMENTEVENTS_ONMOUSEDOWN:
{
return This()->OnHTMLEventClick();
}
break;
}
return E_NOTIMPL;
}
STDMETHODIMP XSZone::OnHTMLEventClick()
{
//AfxMessageBox("in OnHTMLEventClick" );
MSHTML::IHTMLDocument2Ptr spIHTMLDocument2(m_wndDHTMLEdit.GetDom());
// m_wndDHTMLEdit is a instanse of DHTMLEdit Control
MSHTML::IHTMLElementPtr spElement = spIHTMLDocument2->parentWindow->event->srcElement;
CString strElementId = (LPCTSTR)(spElement->id);
Enjoy programming and pray for me.
|
|
|
|
|
Hello, I'm pretty new to using COM and have run into a problem. I have a large structure, consisting of integers, user defined enumerations, several sub-structures and several dynamic arrays. How can I send this user defined type though COM? I'm trying to write my .idl file now to accept this structure... what needs to be done?
My struct is much larger, but this small example should be enough to get me on the right track.
//Example Struct:
typedef struct
{
int index1;
Image_Struct *Image_List;
} My_Struct;
//Image_Struct definition
typedef struct
{
float pixel_x;
float pixel_y;
float pixel_z;
} Image_Struct;
Thank you!
|
|
|
|
|
Take a look at this article on Code Project.
http://www.codeproject.com/atl/udtdemo.asp
Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons
|
|
|
|
|
Hello ChemmieBro,
You basically have to define your structs as User-Defined Types (UDT) in your IDL file. Listed below are examples of My_Struct and Image_Struct defined as UDTs :
typedef
[
uuid(C1B33DAB-A011-41ca-83E0-A7F5AEB01E52),
version(1.0),
helpstring("Image_Struct")
]
struct Image_Struct // Image_Struct definition
{
[helpstring("X pixel position.")] float pixel_x;
[helpstring("Y pixel position.")] float pixel_y;
[helpstring("Z pixel position.")] float pixel_z;
} Image_Struct;
typedef
[
uuid(AC11F3A5-855D-495d-B9CF-17EBA35ACC79),
version(1.0),
helpstring("My_Struct")
]
struct My_Struct // Example Struct
{
[helpstring("index.")] int index1;
[helpstring("The Image_Struct struct.")] Image_Struct* Image_List;
} My_Struct;
It is important that the UDT has got a GUID defined for it. This is defined in the "typedef" attribute for the struct.
Also important is that all your fields -should- be (but not necessarily) automation-compatible types. Only so will your UDT be usable in VB.
After this is done, define your interface and methods normally. Include My_Struct and/or Image_Struct types as parameters as per normal.
Listed below is an example interface that refers to My_Struct :
[
object,
uuid(8F75662A-3CC4-42D1-8F2F-0C98E42594A6),
dual,
helpstring("IImageStructProcessor Interface"),
pointer_default(unique)
]
interface IImageStructProcessor : IDispatch
{
[id(1), helpstring("method ProcessMyStruct")] HRESULT ProcessMyStruct([in, out] My_Struct* pMyStruct);
[id(2), helpstring("method FreeMyStructContents")] HRESULT FreeMyStructContents([in] My_Struct* pMyStruct);
};
I have created some working example codes based on My_Struct, Image_Struct and the IImageStructProcessor interface.
Send an email to me if you want a copy of the example codes. My email address is :
bio_lim_2004@yahoo.com
Best Regards,
Bio.
|
|
|
|
|
Hi Bio,
u seem quite activity in this COM section, have seen quite a few of your reply while I was searching for a solution to my problem. Hope you can help me with this.
In your reply earlier,
Lim Bio Liong wrote:
Also important is that all your fields -should- be (but not necessarily) automation-compatible types. Only so will your UDT be usable in VB.
So does this works for enum also? I think the initial question also include enum as on of the data type. I am also hoping to use some enum in my COM DLL. If it works for enum also, can other languages using my DLL be able to use this struct. Because I was hoping my COM DLL will works with as my languages as possible and not just VB only.
Truth is not always popular, but it is always right.
|
|
|
|
|
Hello w_logan,
>> So does this works for enum also?
Yes. It works also for enum. The following is an example of how to define an automation-compatible enum in IDL :
typedef [uuid(B5051CD9-A577-451b-BDD8-17AC68ED27BB)]
enum
{
enum_value_0 = 0,
enum_value_1 = 1,
enum_value_2 = 2,
enum_value_3 = 3
} EnumValue;
Yes, the "typedef" keyword and the "uuid" attribute is necessary for proper definition of the enum type so that it is automation-compatible.
Thereafter, you may include EnumValue as a type that can be used in your automation-compatible struct, e.g. :
typedef
[
uuid(1F2AFC9C-2ACB-4fc3-A415-8E0736B3C4BB),
version(1.0),
helpstring("My_Struct_VB_2")
]
struct My_Struct_VB_2 // Example Struct
{
[helpstring("index.")] int index1;
[helpstring("The Image_Struct struct.")] Image_Struct Image_List;
[helpstring("EnumValue value.")] EnumValue ev1;
} My_Struct_VB_2;
>> can other languages using my DLL be able to use this struct. Because I was hoping my COM DLL will works with as my languages as possible and not just VB only.
This very much depends on the language's IDE. VB and the Visual C# IDE do support most if not all of the automation-compatible IDL constructs. I haven't used Delphi or the other language IDEs yet so I wouldn't be able to comment on those.
Send me an email and I can send you my sample program.
Best Regards,
Bio.
|
|
|
|
|
Is there a function that creates a GUID froma string, similar to what StringFromGUID2 does but the other way round?
|
|
|
|
|
You can use
RPC_STATUS RPC_ENTRY UuidFromString(<br />
unsigned char* StringUuid,<br />
UUID* Uuid<br />
);
taken from Platform SDK Help.
|
|
|
|
|
Hi,
We have a MFC/VC++ application. We are using a active x button control in our application. I want to get control ID/Window ID(not handle) from the activeX control. How it is possible?.
Thanks & Regards,
Gopalakrishnan
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
with GetDlgCtrlId() we can get the button id.
e.veera raghavendra
|
|
|
|
|
But you cannot get a control id from a active x button control
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
Hi all,
I'm working with a VB 6 app that uses COM componensts utilizing COM+ services on a Windows 2000 Professional machine. These components access and manipulate SQL Server 2000 data. Recently, I've modified a module in the client application just to get an error message in the COM+ component that reads:
"Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction."
I've searched Microsoft.com for this error and found info at this URL:
http://support.microsoft.com/default.aspx?scid=kb;en-us;834849
But the scenario described in the document doesn't match mine. Apparently all code is okay and TransactionMode property of each participating component is perfectly set (to RequiresNewTransaction for root object of the transaction and to UsesTransactions for others) but the error still occurs. An important thing to note is that the error doesn't occur while adding a record. It occurs only when a record is edited and then saved. Even though the same code base is used to perform both the operations.
Please help me solve this issue. Any help or ideas are greatly appreciated.
Regards,
|
|
|
|
|
Hi there!
I have a activex dll written in vc++ 6.0
There is one function that needs to receive a Ado Recordset from a VBasic application. It seems that after the VB does the call to the function, the ADORecordset loses at least one property: Sort.
The function is receiving the ADORecordset as an IDispatch.
Any ideia is a good idea to this problem...
Thanks in advance.
António Carvalho
|
|
|
|
|
Hi there,
I've some problems accessing my ActiveX control from a VBScript/JScript. The control can be successfully initialized and acessed via the <object> tag.
The problem is, that I've to retrieve additional objects/interfaces from the control, which are all defined in the typelib embedded in the control. This looks somehow like this:
var ObjInst = new Object;
ObjInst = Control.GetInstance();
ObjInst.Method();
Because everythings working fine from CPP/VB when compiling, I would like to know, whether I have to register or reference the typelib somehow in the html code or somewhere else, or whatever may cause this error. I can view the typelib in the OLE viewer supplied with visual studio, so the registration can't be that faulty in my opinion. My thoughts were, that acessing a reference to a IDispatch interface should be generally no problem in JScript/VBScript.
Thanks for any suggestions.
Florian
|
|
|
|
|
Hi Florian,
It may not be related, but at work yesterday, I was having a similar problem when trying to use a legacy C++ OCX from a script.
What I found was that the control was written with MFC and was specifically blocking access to the dispatch interface.
I was able to override the IsInvokeAllowed() to return TRUE which solved my problem.
As I said, it may be completely unrelated, but its worth looking into if your control was written using MFC.
Regards
Kev
|
|
|
|
|
Hi Kev,
thanks for your fast reply! Well, the control is originally based on MFC, so I think this is worth a try.
Bye, Florian
|
|
|
|
|
Hi kev,
bad news so far. Overriding doesn't helps here. The function gets called, but generally returning TRUE hasn't had any effect. I changed it for crosschecking to FALSE and got a different error, when trying to invoke the function which returns the IDispatch reference to the internal object I want to expose.
But in general I'm right, when I suppose that JScript/VBScript should automatically generate a wrapper for a returned reference to an IDispatch interface ( IDispatch* in the used function) ? Or have I anything forgotten in that case ? My exposed Control doesn't implements these additional interfaces, but they're all defined and accessible in the corresponding typelibrary.
Bye,
Florian
|
|
|
|
|
Hi Florian,
I'm not too sure if I'm fully understanding your problem - it looked at first glance as if it was the same problem as mine.
To anyone else reading, if I put my foot in it, please correct me - in no way do I claim to be a COM wizard. Just been around the block a couple of times, learning as I go...
Basically, if you access a COM component or control using a scripting language, you're limited to whatever functionality is available on the default interface of the component which must be an IDispatch-based interface. Calls are made simply by the scripting host mapping the method or property name (string) onto an id (int) and passing this id along with parameter information to the IDispatch::Invoke method.
If your control implements only custom (IUnknown-based) interfaces, you won't be able to access its functionality from a scripting language.
If an MFC wizard was used, you'll almost certainly have at least part of your component exposed via a dual interface. If you've added any further secondary interfaces though, these won't be accessible to the scripting language.
Can you give me a bit more detail about your component - maybe attach an IDL file or even the coclass definition from the IDL file?
Kev
|
|
|
|
|