I face the following problem: In Embarcadero project (either exe or dll) there is an exception when I call the libssh2_session_handshake() that establishes and ssh communication between 2 hosts. I have built an .exe in Embarcadero RAD XE5 C++ (the same occurs if I build dll). The project that creates this .exe, has linked statically the libssh2.lib library. When trying to run the exe it loads dynamically the libssh2.dll. The libssh2.lib and the libssh2.dll are built with Visual Studio. I have used various versions of them. The last one built the last code of libssh2 from git hub, with Visual Studio 2015.
From my job it is required these files to be incorporated to Embarcadero project.
In order the libssh2.lib file to be workable in Embarcadero I run the coff2omf.exe tool found in Embarcadero, that converts a .lib from Visual Studio to compatible to embarcadero.
When the code in Embarcadero project calls the libssh2_session_handshake, it constantly raises an exception: "Access violation at address 00000000. Read of address 00000000".
I follow the example https://www.libssh2.org/examples/scp.html, which shows how to send a file to an sftp server, having first created an ssh conection.
Could anyone help to fix that? Do you have any idea what may cause it.
Thank you for you time.
Below I give a part of my code.
rc = libssh2_init(0);
ShowMessage("rc = " + IntToStr(rc));
if(rc) {
fprintf(stderr, "libssh2 initialization failed (%d)\n", rc);
ShowMessage(AnsiString().sprintf("libssh2 initialization failed (%d)",rc));
return 1;
}
sock = socket(AF_INET, SOCK_STREAM, 0);
//Connect to Remote Host
//Prior that the ip of the remote host has been defined (sin)...
if(connect(sock, (struct sockaddr*)(&sin),
sizeof(struct sockaddr_in)) != 0) {
int wsaerr = WSAGetLastError();
ShowMessage("Failed to connect " + IntToStr(wsaerr));
//return -1;
}
try{
rc = libssh2_session_handshake(session, sock);
ShowMessage("libssh2_session_handshake rc: " + IntToStr(rc));
if(rc) {
ShowMessage("Failure establishing SSH session: " + IntToStr(rc));
//return -1;
}
}
catch(Exception &e){
ShowMessage("exception raised " + e.Message());
}