Hi!
How do I connect the Borland C++ Builder 6 with DLL OpenDSSengine using COM object?
I follow the steps for Visual Studio and everything went well, but I have difficulties in borland.
Thank you.
Last edit: gpb83 2016-03-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am not an expert on C++ and I'm not sure why you are doing some of the things, but it looks close. C++ Builder is not supported by embarcadero which also supplies Delphi, the main language for the top part of OpenDSS. Here is what we do in a Delphi program to get a connection to OpenDSS after importing the type library.:
TRYDSSObject:=coDSS.Create;DSSObject.Start(0);EXCEPTOnE:ExceptionDoBeginDoSimpleMsg('The OpenDSS Program does not seem to be installed. You may install it using the installer provided with DGScreener.'+CRLF+E.Message,-29995);Exit;End;END;DSSText:=DSSObject.Text;DSSCircuit:=DSSObject.ActiveCircuit;DSSSolution:=DSSCircuit.Solution;DSSProgressfrm:=DSSObject.DSSProgress;whereDSSObject:IDSS;DSSText:IText;DSSCircuit:ICircuit;DSSSolution:ISolution;DSSProgressfrm:IDSSProgress;
Since both C++ Builder and Delphi are supported in RAD Studio, I gotta believe there are similar wrappers around the COM stuff in both languages.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
1- Install OpenDSS and Register the COM Server like the Getting Started with OpenDSS document
c:\OpenDSS> regsvr32 OpenDSSEngine.DLL
In C++ Builder 6:
1 - Create a Project or use an existing
2 - Click Project, Import Type Library in the BCB IDE. The Import Type Library dialog appears.
3 - In a opened window check the Generate Component Wrapper check box.
4 - In the Import Type Library list box, select the name of the Type Library. In our example, it is the OpenDSSEngine Library (Version 1.0). Press the Create Unit button. The file OpenDSSEngine DLL_TLB.cpp will be added to your project. [1]
5 - Put the include file in your project (OpenDSSEngine DLL_TLB.h )
6 - Write the follow code: [2],[3]
//---------------------------------------------------------------------------#pragma hdrstop#include"OpenDSSengine_TLB.h"//---------------------------------------------------------------------------#include<iostream>#include<string>//using namespace System;usingnamespacestd;#pragma argsusedintmain(intargc,char*argv[]){CoInitialize(NULL);IDSS*DSSObj;HRESULThr=CoCreateInstance(CLSID_DSS,NULL,CLSCTX_INPROC_SERVER,IID_IDSS,(void**)&DSSObj);if(SUCCEEDED(hr)){cout<<DSSObj->Version<<endl;Opendssengine_tlb::ITextPtrDSSText;Opendssengine_tlb::ICircuitPtrDSSCircuit;Opendssengine_tlb::ISolutionPtrDSSSolution;if(DSSObj->Start(0)){cout<<"openDSS Loaded!"<<endl;DSSText=DSSObj->Text;DSSCircuit=DSSObj->ActiveCircuit;DSSSolution=DSSCircuit->Solution;cout<<DSSObj->Version<<endl;DSSText->set_Command(L"clear");DSSText->set_Command(L"Compile (IEEE123Master.dss)");DSSSolution->Solve();DSSText->set_Command(L"Show Voltage LN Nodes");}DSSObj->Release();}CoUninitialize();return0;}//---------------------------------------------------------------------------
7- Build and Make - Run.
PS: Conversion is necessary: 'wchar_t ' to 'const char ' [4]
Hi!
How do I connect the Borland C++ Builder 6 with DLL OpenDSSengine using COM object?
I follow the steps for Visual Studio and everything went well, but I have difficulties in borland.
Thank you.
Last edit: gpb83 2016-03-15
Ok.

I follow the tutorial in this link to insert the library
tutorial
It´s work, But in:
" if (DSSObj->Start(0)) " comes the following error
And in " //DSSText->Command = L"clear";" the error appears when compiling
Last edit: gpb83 2016-03-15
I am not an expert on C++ and I'm not sure why you are doing some of the things, but it looks close. C++ Builder is not supported by embarcadero which also supplies Delphi, the main language for the top part of OpenDSS. Here is what we do in a Delphi program to get a connection to OpenDSS after importing the type library.:
Since both C++ Builder and Delphi are supported in RAD Studio, I gotta believe there are similar wrappers around the COM stuff in both languages.
The previous post should read '...is now supported ..."
OK, thanks for your help.
I found a answer. It worked for me.
The procedure is as follows:
1- Install OpenDSS and Register the COM Server like the Getting Started with OpenDSS document
c:\OpenDSS> regsvr32 OpenDSSEngine.DLL
In C++ Builder 6:
1 - Create a Project or use an existing
2 - Click Project, Import Type Library in the BCB IDE. The Import Type Library dialog appears.
3 - In a opened window check the Generate Component Wrapper check box.
4 - In the Import Type Library list box, select the name of the Type Library. In our example, it is the OpenDSSEngine Library (Version 1.0). Press the Create Unit button. The file OpenDSSEngine DLL_TLB.cpp will be added to your project. [1]
5 - Put the include file in your project (OpenDSSEngine DLL_TLB.h )
6 - Write the follow code: [2],[3]
7- Build and Make - Run.
PS: Conversion is necessary: 'wchar_t ' to 'const char ' [4]
References
1 - Import LIbrary
2 - COM in Builder C++
3 - How to use COM
4 - Wchar to const char
Last edit: gpb83 2016-03-17
How can I connect with c++ using opendss DIRECT way ?
Hello,
Check this out:
https://stackoverflow.com/questions/1922580/import-a-dll-with-c-win32
Best regards
Davis
Hi Davis, thank you.
This work's.
My mistake was that I needed all the opendss dlls in the folder.
but now I need to retrieves all functions address with GetProcAddress?
Can you give me a sample?
Last edit: gpb83 2020-02-18
Hello,
We provide a header file for that:
https://sourceforge.net/p/electricdss/code/HEAD/tree/trunk/Version8/Distrib/x64/OpenDSSDirect.h
Try it, and see how it works.
Best regards
Davis