Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. Parameter in ActiveX control

Parameter in ActiveX control

Scheduled Pinned Locked Moved COM
com
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TrungHuynh
    wrote on last edited by
    #1

    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 }

    S 1 Reply Last reply
    0
    • T TrungHuynh

      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 }

      S Offline
      S Offline
      Steve S
      wrote on last edited by
      #2

      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

      T 1 Reply Last reply
      0
      • S Steve S

        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

        T Offline
        T Offline
        TrungHuynh
        wrote on last edited by
        #3

        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

        S 1 Reply Last reply
        0
        • T TrungHuynh

          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

          S Offline
          S Offline
          Steve S
          wrote on last edited by
          #4

          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

          T 1 Reply Last reply
          0
          • S Steve S

            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

            T Offline
            T Offline
            TrungHuynh
            wrote on last edited by
            #5

            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

            S 1 Reply Last reply
            0
            • T TrungHuynh

              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

              S Offline
              S Offline
              Steve S
              wrote on last edited by
              #6

              Firstly, you should give MIDL some hint about your parameter. Is it being passed into the function ([in] FILE_INFO FileInfo) or being passed back? ([out] FILE_INFO* FileInfo). Secondly, it's customary for methods to return a status indication (or HRESULT) so that you can easily determine that an error has occurred. To use a UDT, assign a GUID to the structure definition. Something like this will help. #ifdef __midl [ uuid(FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF), version(1.0), helpstring("My FILEINFO structure") ] #else struct __declspec(uuid("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF")) FILE_INFO; typedef #endif struct FILE_INFO { BSTR szFileName; BSTR szLocation; BSTR szLocationTemp; } FILE_INFO; except you'd replace the dummy guid FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF with your own. You should then have [id(7)] HRESULT SetInfo([in] struct FILE_INFO* pFileInfo); Note that it's a pointer you pass in now, not a structure. UDTs must be passed by reference, not by value. I suggest you read the MSDN articles located by searching for UDT IDL parameter and if you're going to do a lot of this, read the Martin Gudgin book, Essential IDL. Steve S

              T 2 Replies Last reply
              0
              • S Steve S

                Firstly, you should give MIDL some hint about your parameter. Is it being passed into the function ([in] FILE_INFO FileInfo) or being passed back? ([out] FILE_INFO* FileInfo). Secondly, it's customary for methods to return a status indication (or HRESULT) so that you can easily determine that an error has occurred. To use a UDT, assign a GUID to the structure definition. Something like this will help. #ifdef __midl [ uuid(FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF), version(1.0), helpstring("My FILEINFO structure") ] #else struct __declspec(uuid("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF")) FILE_INFO; typedef #endif struct FILE_INFO { BSTR szFileName; BSTR szLocation; BSTR szLocationTemp; } FILE_INFO; except you'd replace the dummy guid FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF with your own. You should then have [id(7)] HRESULT SetInfo([in] struct FILE_INFO* pFileInfo); Note that it's a pointer you pass in now, not a structure. UDTs must be passed by reference, not by value. I suggest you read the MSDN articles located by searching for UDT IDL parameter and if you're going to do a lot of this, read the Martin Gudgin book, Essential IDL. Steve S

                T Offline
                T Offline
                TrungHuynh
                wrote on last edited by
                #7

                In odl file is ok but in .h file and .cpp, how can i define a type of FILE_INFO code: In .h file afx_msg void SetSCOFileInfo(FILE_INFO* pFileInfo); In .cpp file BEGIN_DISPATCH_MAP(CEditorLoaderCtrl, COleControl) //{{AFX_DISPATCH_MAP(CEditorLoaderCtrl) DISP_FUNCTION(CEditorLoaderCtrl, "SetSCOFileInfo", SetSCOFileInfo, VT_EMPTY,"what does type we deine") //}}AFX_DISPATCH_MAP END_DISPATCH_MAP() When i launch to ClassWizard, it will appears error Parsing error: "FILE_INFO*" is not a valid OLE parameter type Input line: afx_msg void SetSCOFileInfo(FILE_INFO* pFileInfo)

                1 Reply Last reply
                0
                • S Steve S

                  Firstly, you should give MIDL some hint about your parameter. Is it being passed into the function ([in] FILE_INFO FileInfo) or being passed back? ([out] FILE_INFO* FileInfo). Secondly, it's customary for methods to return a status indication (or HRESULT) so that you can easily determine that an error has occurred. To use a UDT, assign a GUID to the structure definition. Something like this will help. #ifdef __midl [ uuid(FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF), version(1.0), helpstring("My FILEINFO structure") ] #else struct __declspec(uuid("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF")) FILE_INFO; typedef #endif struct FILE_INFO { BSTR szFileName; BSTR szLocation; BSTR szLocationTemp; } FILE_INFO; except you'd replace the dummy guid FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF with your own. You should then have [id(7)] HRESULT SetInfo([in] struct FILE_INFO* pFileInfo); Note that it's a pointer you pass in now, not a structure. UDTs must be passed by reference, not by value. I suggest you read the MSDN articles located by searching for UDT IDL parameter and if you're going to do a lot of this, read the Martin Gudgin book, Essential IDL. Steve S

                  T Offline
                  T Offline
                  TrungHuynh
                  wrote on last edited by
                  #8

                  in .odl file is ok But how can define .h and .cpp file of ActiveX control In .h file afx_msg void SetInfo(FILE_INFO* lpFileInfo); In .cpp file BEGIN_DISPATCH_MAP(CEditorLoaderCtrl, COleControl) DISP_FUNCTION(CEditorLoaderCtrl, "SetInfo", SetInfo, VT_EMPTY, "what kind of type we define(VTS_BSTR;VTS_VARIANT...)") END_DISPATCH_MAP() if we ignore define in cpp file, when we launch to ClassWizard, it will appears an error Parsing error:"FILE_INFO*" is not a valid OLE type line:"afx_msg void SetInfo(FILE_INFO* lpFileInfo)"

                  S 1 Reply Last reply
                  0
                  • T TrungHuynh

                    in .odl file is ok But how can define .h and .cpp file of ActiveX control In .h file afx_msg void SetInfo(FILE_INFO* lpFileInfo); In .cpp file BEGIN_DISPATCH_MAP(CEditorLoaderCtrl, COleControl) DISP_FUNCTION(CEditorLoaderCtrl, "SetInfo", SetInfo, VT_EMPTY, "what kind of type we define(VTS_BSTR;VTS_VARIANT...)") END_DISPATCH_MAP() if we ignore define in cpp file, when we launch to ClassWizard, it will appears an error Parsing error:"FILE_INFO*" is not a valid OLE type line:"afx_msg void SetInfo(FILE_INFO* lpFileInfo)"

                    S Offline
                    S Offline
                    Steve S
                    wrote on last edited by
                    #9

                    And there's your problem. The ClassWizard will only allow you to use OLE Automation compatible types. You can "cheat", because the control is in-process, so there isn't any real marshalling being done, by defining the parameter as a VARIANT, then using the fact that a variant will hold a void*, which you'll need to cast back in your control to be a FILE_INFO*. But you didn't hear it from me.... This definitely should NOT be considered as an option if there is ANY chance that it will be used out of process, where it won't work. Steve S

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups