SelectByID2 / SelectByID throw exceptions

Hallo,

as the titles says i have big trouble with the select functions in solid works. sometimes they work, sometimes they don't. I have not the slightest idea what causes it. The code appears to work fine then at some point this function gives up and refuses to work anymore - without that i even touch it. When this happens i usually restart, which never works, i run through nonsense calls like SelectByID2( L"", L"", 0, 0, 0, VARIANT_TRUE, 0, NULL, swSelectOptionDefault, &RetVal ), i clear the selections, run some more nonsense until, like magic, it starts to work again. it keeps running perfectly for a day or an hour until this API throws exceptions again. I searched in the internet and found many people experiencing crashes with this function. Could anyone here help to pinpoint what the problem really is?

Here's an example, the select call to get that edge is nonsense again - but it should not crash. when SelectByID2 is in a friendly mood it runs through. I do work in a multithread environment, but the code is linear and nothing intereferes with that. It is this function only which makes a mess, i never experienced something quite like this (before i had to integrate selctions into my code, that is).

Thank you very very much for you help!

Best Regards,

Paul

CComPtr App;

CoInitializeEx( NULL, COINIT_MULTITHREADED );

HRESULT hres = App.CoCreateInstance(__uuidof(SldWorks), NULL, CLSCTX_LOCAL_SERVER);

BSTR PartTemplate;
App->GetUserPreferenceStringValue( swDefaultTemplatePart, &PartTemplate );

CComPtr Result;
App->NewDocument( PartTemplate, 0, 0, 0, &Result );

CComPtr MyModel;
MyModel = Result;

CComPtr MyModelDocExtension;

MyModel->get_Extension( &MyModelDocExtension );

VARIANT_BOOL RetVal;
MyModelDocExtension->SelectByID2( L"", L"EDGE", 0, 0, 0, VARIANT_FALSE, 0, NULL, swSelectOptionDefault, &RetVal );

Results in: Unhandled exception at 0x766f9b30 in XXXXXXXXXX.exe: 0xC0000005: Access violation reading location 0x00e3e000

SolidworksApi macros