Jump to content
  • Advertisement
Sign in to follow this  
sakky

COM questions

This topic is 5410 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, thanks you’re some of your help I’ve gotten farther now. I still have some problems, Hopefully, I’ll be able to take the advice given to me this time; sorry for that ;) I’ve read some tutorials on CodeProject about COM. I’m practicing with it right now and I really have to know a few things. 1st Do I really have to use a class factory? 2nd Do I have to write a server for my COM objects? I’m also getting these errors when trying to compile the my project. I’m using VC++.NET and I’ve created a Win32 DLL application. Is there some project options I’m missing? Here are the errors: error C2373: 'DllGetClassObject' : redefinition; different type modifiers error C2373: 'DllCanUnloadNow' : redefinition; different type modifiers

Share this post


Link to post
Share on other sites
Advertisement
I'd guess the dllexport tag isn't the same in the declaration and definition of those functions, something doesn't match.

To be COMpliant you need a class-factory and something has to use your object.

I wrote a crude tutorial some time ago.

Share this post


Link to post
Share on other sites
Do you want to here something really stupid! I inserted the WINAPI prefix and the DLL compiled fine. These are the results

------ Build started: Project: SCBAR, Configuration: Debug Win32 ------

Compiling...
SCBAR.CPP
Linking...
SCBAR.def : warning LNK4104: export of symbol 'DllGetClassObject' should be PRIVATE
SCBAR.def : warning LNK4104: export of symbol 'DllCanUnloadNow' should be PRIVATE
Creating library Debug/SCBAR.lib and object Debug/SCBAR.exp

Build log was saved at "file://c:\Documents and Settings\Matthew R. Erdman\My Documents\SCBAR\Debug\BuildLog.htm"
SCBAR - 0 error(s), 2 warning(s)


---------------------- Done ----------------------

Build: 1 succeeded, 0 failed, 0 skipped

What the heck man? It was just the WINAPI prefix. I need to get a really good book on COM. Do you have any recommendations?

Would it be hard to build your own COM type library? I just wanted to know because I think I might get a better understanding of how COM works if I implement my own library.

Share this post


Link to post
Share on other sites
They're just warnings. Look up that warning code in the MSDN and you get:
Quote:

export of symbol "symbol" should be PRIVATE
The symbol can be one of the following:

  • DllRegisterServer
  • DllRegisterServerEx
  • DllUnregisterServer
  • DllGetClassObject
  • DllCanUnloadNow

This warning is emitted when you are building an import library for a DLL and export one of the above functions without specifying it as PRIVATE in the module-definition file. In general these functions are exported for use only by OLE. Placing them in the import library can lead to unusual behavior when a program linked to the library incorrectly makes calls to them.


It helps if you use a module definition file. Create a file called "exports.def", and add it to your project. Open it, and put the following into it:

EXPORTS
DllGetClassObject PRIVATE
DllCanUnloadNow PRIVATE
DllRegisterServer PRIVATE
DllUnregisterServer PRIVATE



Then just recompile, and MSVC will read the exports from the .def file. I'm not sure how to declare functions as private without using a .def file, but theres almost certainly a way.

Share this post


Link to post
Share on other sites
Oh, I am using a module definition file. Except I’m not using PRIVATE, I’m using @n where n is a number starting from 1 to the number of exported functions in the file. Here is the source to my .DEF file.


LIBRARY SCBAR

EXPORTS
DllGetClassObject @1
DllCanUnloadNow @2



I just switched to your way Evil Steve, and I got no warnings. The tutorial I was reading said that DllRegisterServer & DllUnregisterServer are not needed. So I didn’t define them.

Share this post


Link to post
Share on other sites
Do I have to define my own versions of DllRegisterServer or DllUnregiserServer or can I just have Setup.exe install these for me? Because the code I’m getting off MSDN is full of errors and will not compile for any thing.

I figured if I could save me the trouble, I would just use an installer to register the components instead of my writing functions to do it. Because I don’t quite understand how it works. The examples I get from CodeProject and MSDN are littered with errors and use functions that are not defined any where.

Please help?

Share this post


Link to post
Share on other sites
In most cases an installer registers a COM library by loading the library, performing a GetProcAddress on DllRegisterServer and registers the library using the DllRegisterServer function. Same with unregistering a COM library. You should provide your on DllRegisterServer / DllUnregisterServer functions, they don't have to do any more than set a few registry keys.

The article and code at this site should be helpful:


Magius

Share this post


Link to post
Share on other sites
I’m getting the LNK4017 error on the COM Dll.* server functions. I can’t figure out why I’m getting the errors because my definitions of functions are the same as MSDN. My .def file uses PRIVATE and I still get the errors I tries switching to the @ symbols with numbers and I still get errors. Why isn’t the linker exporting the functions? Is there a __declspec I should be using on those functions?

Share this post


Link to post
Share on other sites
Okay, I figured that out. The reason why it wasn’t finding the functions was because the linker wasn’t linking them properly. The reason why the linker wasn’t linking them properly was because the definition file. I forgot to put the EXPORTS above my exports.

Now I see my ShortCutBar on the Toolbars menu but the toolbar isn’t showing up. This sucks. It’s always one thing after another. At least all this is teaching me a bunch about COM; even if I’m having lots of problems with it.

But, thanks for all your guys help. I really appreciate all of what you guys have been doing :) I owe you guys one ;D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!