Exporting enum types to a COM DLL
-
Hi I'm very new to the Windows/COM development environment (coming from embedded/Unix). I'd like to create a COM/DLL (using C++) that contains and exports an enum type. I want the enum type to show up in the Visual Studio Object browser after I add the DLL to the "References" folder in the client application. I've used "[export]" before the enum in the header file. I've also tried including the header file in the serverdll.idl file. So far the enum hasn't showed up in the Object Browser. Any help or suggestions would be appriciated. Thanks Robert Ernst codeproject@theernsts.org
-
Hi I'm very new to the Windows/COM development environment (coming from embedded/Unix). I'd like to create a COM/DLL (using C++) that contains and exports an enum type. I want the enum type to show up in the Visual Studio Object browser after I add the DLL to the "References" folder in the client application. I've used "[export]" before the enum in the header file. I've also tried including the header file in the serverdll.idl file. So far the enum hasn't showed up in the Object Browser. Any help or suggestions would be appriciated. Thanks Robert Ernst codeproject@theernsts.org
open the .idl file of the interface put the definition of the enum inside the Library after the definition of the coclass as follows typedef enum tagEchoType { EchoTypeHelloWorld = 0, EchoTypeGoodbyeWorld = 1 } EchoType; thats enough Knock out 't' from can't, You can if you think you can :cool: -- modified at 1:54 Friday 19th May, 2006
-
open the .idl file of the interface put the definition of the enum inside the Library after the definition of the coclass as follows typedef enum tagEchoType { EchoTypeHelloWorld = 0, EchoTypeGoodbyeWorld = 1 } EchoType; thats enough Knock out 't' from can't, You can if you think you can :cool: -- modified at 1:54 Friday 19th May, 2006
I've tried placing the enum in the .idl file, but the type still doesn't show up in the DLL, based on browsing with the Object Viewer I've inserted the enum in the .idl file both manually, and using attributes: So I have: File: employee.cpp #include [ module(dll, name = "TestEmployee", helpstring = "TestEmployee 1.0 Type Library") ]; [ emitidl ]; [dual] __interface IEmployee : IDispatch { [id(1)] HRESULT DoWork(BSTR bstrTask); }; [export] enum Status {EMPLOYEED, UNEMPLOYEED} Status_t; File:employee.idl ... [ uuid(38884C05-8FF2-3A53-83D3-837E34D61785), dual ] #line 27 "c:\\samples\\com\\employee.cpp" interface IEmployee : IDispatch { #line 29 "c:\\samples\\com\\employee.cpp" [id(1)] HRESULT DoWork([in]BSTR bstrTask); }; #line 33 "c:\\samples\\com\\employee.cpp" enum Status { EMPLOYEED = 0, UNEMPLOYEED = 1, }; The linker command is: cl employee.cpp /LD /link /IDLOUT:employee.idl Am I missing something in the Linker command? Thanks Robert Ernst
-
I've tried placing the enum in the .idl file, but the type still doesn't show up in the DLL, based on browsing with the Object Viewer I've inserted the enum in the .idl file both manually, and using attributes: So I have: File: employee.cpp #include [ module(dll, name = "TestEmployee", helpstring = "TestEmployee 1.0 Type Library") ]; [ emitidl ]; [dual] __interface IEmployee : IDispatch { [id(1)] HRESULT DoWork(BSTR bstrTask); }; [export] enum Status {EMPLOYEED, UNEMPLOYEED} Status_t; File:employee.idl ... [ uuid(38884C05-8FF2-3A53-83D3-837E34D61785), dual ] #line 27 "c:\\samples\\com\\employee.cpp" interface IEmployee : IDispatch { #line 29 "c:\\samples\\com\\employee.cpp" [id(1)] HRESULT DoWork([in]BSTR bstrTask); }; #line 33 "c:\\samples\\com\\employee.cpp" enum Status { EMPLOYEED = 0, UNEMPLOYEED = 1, }; The linker command is: cl employee.cpp /LD /link /IDLOUT:employee.idl Am I missing something in the Linker command? Thanks Robert Ernst
Robert Ernst wrote:
I've tried placing the enum in the .idl file, but the type still doesn't show up in the DLL, based on browsing with the Object Viewer
The following code is generated by the Application wizard of the ATL COM Componenet. I am simply added the enum inside the code is works fine. I have tested under VB6.0 and VC++6.0 Object Browser
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(7CB363A8-69EB-48BE-9E20-BD1B5CC87F76),
dual,
helpstring("Itest Interface"),
pointer_default(unique)
]
interface Itest : IDispatch
{
};[
uuid(8D40959D-E348-4220-971A-61CA27F53C45),
version(1.0),
helpstring("test11 1.0 Type Library")
]
library TEST11Lib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");\[ uuid(8F71F9BF-8982-4804-A22C-FA3A7E7C225C), helpstring("test Class") \] coclass test { \[default\] interface Itest; }; typedef enum tagTestEnum { Bad=0, Good=1 }TestEnum;
};
Hope this code helps you Knock out 't' from can't, You can if you think you can :cool:
-
Robert Ernst wrote:
I've tried placing the enum in the .idl file, but the type still doesn't show up in the DLL, based on browsing with the Object Viewer
The following code is generated by the Application wizard of the ATL COM Componenet. I am simply added the enum inside the code is works fine. I have tested under VB6.0 and VC++6.0 Object Browser
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(7CB363A8-69EB-48BE-9E20-BD1B5CC87F76),
dual,
helpstring("Itest Interface"),
pointer_default(unique)
]
interface Itest : IDispatch
{
};[
uuid(8D40959D-E348-4220-971A-61CA27F53C45),
version(1.0),
helpstring("test11 1.0 Type Library")
]
library TEST11Lib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");\[ uuid(8F71F9BF-8982-4804-A22C-FA3A7E7C225C), helpstring("test Class") \] coclass test { \[default\] interface Itest; }; typedef enum tagTestEnum { Bad=0, Good=1 }TestEnum;
};
Hope this code helps you Knock out 't' from can't, You can if you think you can :cool:
BINGO!! That was it. My enum definition wasn't inside the library TEST11Lib {} declaration. Once I placed it inside the library {} block it worked. Thanks so much for your help! Robert Ernst codeproject@theernsts.org