We have an application that uses the com api of MicroStation.
With the microstation application MicroStation V8i the following code worked.
In the progress of updating to MicroStation Connect we have an issue with the function CreateCellElement1.
As a simplified example, we are using the following code:
For the _com_error we sometimes got the hr response: 0x80020010 and sometimes 0x80010105 RPC_E_SERVERFAULT.
Apparently microstation crashes when the CreateCellElement1 function is called. In the attachment is also the crash dump.
Do you have any ideas how we can fix this issue?
Inserted code
#import "microstation.exe" //#import "microstaion.tlh" MicroStationDGN::_ModelReferencePtr model= createModel("model"); model->Activate(); MicroStationDGN::Point3d p1{ 0, 0, 0 }; MicroStationDGN::Point3d p2{ 1, 0, 0 }; MicroStationDGN::Point3d p3{1, 1, 0}; MicroStationDGN::Point3d p4{ 0, 1, 0 }; constexpr int numberOfEntries = 4; MicroStationDGN::_ElementPtr lineArrayPtr[numberOfEntries]; lineArrayPtr[0] = m_appPtr->CreateLineElement2(nullptr, &p1, &p2); lineArrayPtr[1] = m_appPtr->CreateLineElement2(nullptr, &p2, &p4); lineArrayPtr[2] = m_appPtr->CreateLineElement2(nullptr, &p1, &p3); lineArrayPtr[3] = m_appPtr->CreateLineElement2(nullptr, &p3, &p4); SAFEARRAY* psa = nullptr; try { const LONG count = numberOfEntries; ATL::CComSafeArray<LPDISPATCH> sa(count); for (LONG i = 0; i < count; i++) { sa[i] = lineArrayPtr[i].GetInterfacePtr(); } psa = sa.Detach(); } catch (const CAtlException& e) { return; } MicroStationDGN::_ElementPtr cellElm = m_appPtr->CreateCellElement1(qPrintable("My Cell"), &psa, &p1, true); //Here Hresult returned: HRESULT hr = m_appPtr->ActiveModelReference->AddElement(cellElm); //model->AddElement(cellElm); //To add this direclty into
Hi Leonard,
Leonard Westkamp said:As a simplified example, we are using the following code:
I recommend to do not copy/paste the code directly, but to use Insert > Insert code tool, when any code snippets is shared.
Leonard Westkamp said:For the _com_error we sometimes got the hr response: 0x80020010 and sometimes 0x80010105 RPC_E_SERVERFAULT.
Did you search for the mentioned errors in programming forums? Both were discussed several times (not only in MicroStation Programming).
Leonard Westkamp said:In the progress of updating to MicroStation Connect we have an issue with the function CreateCellElement1.
Please respect the best practices and to specify the used version exactly. There were about 20 different versions of MicroStation CONNECT Edition released so far.
Leonard Westkamp said:With the microstation application MicroStation V8i the following code worked.
What your application is? Is it 32bit or was it migrated to be 64bit, to be the same as MicroStation itself?
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hi Leonard Westkamp
Please be aware MicroStation V8i treated strings primarily by defaults as ASCII, where as MicroStation CONNECT treats strings primarily as wide strings. Your code may require modifications accordingly.
Leonard Westkamp said:In the attachment is also the crash dump.
I do not find a crash dump available to review, if you have it please attach so we can identify the fingerprint of the issue.
Lastly, it would be advisable to perform as few communications as possible (and reliably) over COM and move custom (MDL) code to run in-process natively, then and only then use COM to transfer data/results if/as needed - as a best practice. This saves a lot of time and effort troubleshooting issues when you can debug, maintain, and execute code in their respective (native/managed) layers.
HTH,Bob
Leonard Westkamp said:We have a C++ application that uses the com api of MicroStation
Why use the COM API from a C++ app? The MicroStationAPI is complete. It includes the classes used to implement a primitive command (DgnPrimitiveTool). MicroStation VBA uses the MicroStationAPI to implement its comparatively limited classes.
DgnPrimitiveTool
Regards, Jon Summers LA Solutions
Hi Jan,Thank you for your respone. I hope I updated the thread correctlyCurrently I tried it with the 32bit application, but I will try it now with the 64bit version of our application
Leonard Westkamp said:I hope I updated the thread correctly
Thanks, the code is much nicer now :-)
Leonard Westkamp said:Currently I tried it with the 32bit application, but I will try it now with the 64bit version of our application
To access 64bit process from 32bit one (and vice versa) was discussed many times. Many options are not possible (e.g. to use 64bit dll from 32bit process), but COM allows it in some way. But, if I understand it right, this feature is not ensured automatically and both client and server have to be implemented in the right way and aware of "different bitness".
I agree with Bob and Jon that there are not good reasons to use COM API at all. To implement MicroStation-dependent logic directly in MicroStation, using extremely powerful CE C++ API, is recommended. And this code can communicate, e.g. using some IPC method, with the rest of the application. I know that many applications, integrated with MicroStation, work this way.
Hi Robert Hook, thank you for your response.The wide strings were definalty part of the problem.I uploaded the crash dump via the file secure upload, as it didnt worked with inserting the file directly. Are you not able to see it?
Transfering to MDL is probably a good idea, will look into it.
Mainly because the existing application used the COM API. I will take a look into the MicroStationAPI
Hi Leonard Westkamp,
Leonard Westkamp said:via the file secure upload
Thank you for clarifying it was not an attachment.
Leonard Westkamp said:Are you not able to see it?
Although there were several file names to guess and pick through, I did find the (2 same/identical) small memory dmp files you submitted and I reviewed (what I could, since they are small MS_MINIDUMPTYPE=4 vs large MS_MINIDUMPTYPE=7). I do believe the small memory dump was sufficient to ask my next question since the call stack is approx. 70% Microsoft COM API failing on (1) input queue element it was processing - A (1) Data Point.
When running your application, is MicroStation (application) Visible - able to display views - to send your Data Point?
If not, try making MicroStation (view) Visible and see if you can get further.
Thank you,Bob
Hi all,
there a known issue with all COM methods accepting an array of elements as input parameter. This issue occurs only if these COM functions are called from extern applications and is affecting these methods:
Hi Artur,
thanks for the details.
Artur Goldsweer said:there a known issue with all COM methods accepting an array of elements as input parameter.
Does it mean both direct COM acces (e.g. from C++) and "COM based" layers (like Interop) are affected by this bug?