CoInitializeEx... safe to run on main thread? menu

User Tag List

Results 1 to 8 of 8
  1. #1
    bad6oy30's Avatar Member Authenticator enabled
    Reputation
    1
    Join Date
    Dec 2010
    Posts
    41
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CoInitializeEx... safe to run on main thread?

    I'm moving from out-of-process to in-process, and I have to reinvent the wheel as far as injection and detour goes... using someone else's lib is like paying someone to build my hobby-car

    I want to use c# to do the work. Is it OK to initialize COM on wow's main thread (in an endscene detour that will be doing my work)?

    If not, I can use a worker thread approach and just put a signal-and-wait in the endscene detour... but then does my worker thread need to adopt the main thread's TLS for wow's functions work behave right?

    CoInitializeEx... safe to run on main thread?
  2. #2
    adaephon's Avatar Active Member
    Reputation
    76
    Join Date
    May 2009
    Posts
    167
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Reading from MSDN here CoInitializeEx Function (COM) there is nothing to indicate it would be a problem. However, whether you can or not is possibly secondary to the question of whether you should or not... why do you need to call CoInitializeEx? Especially as you mention using C#. Plenty of people on this forum use C# injected and called through EndScene hooks, and I know that I've never had to play around with the COM library, and nor have I heard anyone else mention it.

    [Edit] Changed link to CoInitializeEx due to mispaste...
    Last edited by adaephon; 02-13-2011 at 11:07 PM. Reason: Update link

  3. #3
    bad6oy30's Avatar Member Authenticator enabled
    Reputation
    1
    Join Date
    Dec 2010
    Posts
    41
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My mistake... I thought it was required to inject .net dll's. I found CorBindToRuntimeEx so I'm good. Sorry for the confusion.

    I might just stay in c++ anyway

  4. #4
    adaephon's Avatar Active Member
    Reputation
    76
    Join Date
    May 2009
    Posts
    167
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're intending to host .NET 4 you'll need to look at the new interfaces for hosting. CorBindToRuntime(Ex) have been deprecated for CLR4 and beyond, and new interfaces are backwards compatible.

  5. #5
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still use the old interface for binding the runtime, since IIRC it's a couple fewer steps. But yeah, it's deprecated so you're probably out of luck if you want to bind with the old call pattern beyond .Net 4.0
    Don't believe everything you think.

  6. #6
    ddebug's Avatar Contributor
    Reputation
    114
    Join Date
    Sep 2010
    Posts
    117
    Thanks G/R
    0/5
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Injecting managed code into an unmanaged process causes lots of headaches if you don't know how to properly marshal stuff. I recommend that you avoid it altogether, if possible.

    IMO, just do it in C++ if you have the knowledge to... Save yourself the trouble.

  7. #7
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by ddebug View Post
    Injecting managed code into an unmanaged process causes lots of headaches if you don't know how to properly marshal stuff. I recommend that you avoid it altogether, if possible.

    IMO, just do it in C++ if you have the knowledge to... Save yourself the trouble.
    ?

    Having been doing this for... a long time now, I'm not entirely sure what you're getting at.

    Managed to unmanaged code marshalling can be tricky, but then again, so can C calling conventions, or smart pointers, or the STL. It's all a matter of what you're familiar with. If you're more productive writing code in a .Net language, then injecting the framework into WoW is the best choice, hands down. In the programming language wars, the winner is ALWAYS "the language you're most familiar with, that can get the job done."
    Don't believe everything you think.

  8. #8
    adaephon's Avatar Active Member
    Reputation
    76
    Join Date
    May 2009
    Posts
    167
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by amadmonk View Post
    I still use the old interface for binding the runtime, since IIRC it's a couple fewer steps. But yeah, it's deprecated so you're probably out of luck if you want to bind with the old call pattern beyond .Net 4.0
    Using .Net 4? I could never get the old interfaces to work. Either way its not hard. Maybe 5 lines extra

Similar Threads

  1. Do LUA addons execute in Wow's main thread?
    By ggg898 in forum WoW Memory Editing
    Replies: 15
    Last Post: 01-12-2020, 01:32 PM
  2. Replies: 4
    Last Post: 10-01-2013, 10:11 AM
  3. Executing injected code on main thread
    By mozartmclaus in forum Diablo 3 Memory Editing
    Replies: 0
    Last Post: 05-23-2012, 03:04 PM
  4. main thread doesnt resume once ollydbg attaches
    By namreeb in forum WoW Memory Editing
    Replies: 7
    Last Post: 07-16-2009, 09:46 PM
  5. Out of the main thread
    By Shamun in forum WoW Memory Editing
    Replies: 11
    Last Post: 12-20-2008, 06:36 AM
All times are GMT -5. The time now is 08:53 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search