Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a C++ dll

Status
Not open for further replies.

shester1452

Programmer
Oct 22, 2007
8
US
Hi all. I am new to the forum. I have run into a situation I could really use some help with. I have a legacy app written in Fujitsu COBOL that I am trying to call a c++ dll. When I try to execute the app I get the error message "The application failed to initialize properly(0x00000005)." Any help would be greatly appreciated.

Thanks.

Steve
 
Refer to thread209-1402415.

Beyond that, do you know the full specs, including the call type of the function in the DLL you're trying to call?

 
I have gone through the samples. I haven't been able to get it work using those examples. My c isn't great. I believe the problem is in the C. Here is the code:

// This is the main DLL file.

#include "stdlib.h"
#include "stdio.h"
#include "stdafx.h"
#include "Bridge.h"



extern "C" {
#include <string.h>
}


#using "dotNetAssembly\bin\dotNetAssembly.dll"

using namespace System;
using namespace dotNetAssembly;


extern "C"
{

__declspec(dllexport) char * decrypt_pin(char *input)
{

String __gc *managed_input = new String(input);

mcDotNetClass __gc *DotNetObject;

DotNetObject = new mcDotNetClass;
System::Diagnostics::Debugger::Log(1, "Made it past new", "Made it past new");

char tmp __gc[] = System::Text::Encoding::UTF8->GetBytes(DotNetObject->DecryptPin(input));
char __pin *value = &tmp[0];

//strncpy(input, value, 4); //Max pin size should be 4

return value;

}

__declspec(dllexport) int Done(char *input, char *output)
{
try
{

String __gc *managed_input = new String(input);

mcDotNetClass __gc *DotNetObject;

DotNetObject = new mcDotNetClass;
System::Diagnostics::Debugger::Log(1, "Made it past new", "Made it past new");

char tmp __gc[] = System::Text::Encoding::UTF8->GetBytes(DotNetObject->DecryptPin(input));
char __pin *value = &tmp[0];

strncpy(output, value, tmp->Length); //Max pin size should be 4
return tmp->Length;
}
catch (...)
{
return 0;
}

}
__declspec(dllexport) int bint(int input)
{

mcDotNetClass __gc *DotNetObject;

DotNetObject = new mcDotNetClass;

return DotNetObject->test_integer(input);

}

__declspec(dllexport) char * bst(char *input, int buflen)
{

String __gc *managed_input = new String(input);

mcDotNetClass __gc *DotNetObject;

DotNetObject = new mcDotNetClass;

char tmp __gc[] = System::Text::Encoding::UTF8->GetBytes(DotNetObject->test_string(input));
char __pin *value = &tmp[0];

strncpy(input, value, buflen);

return input;

}

__declspec(dllexport) int barr(int *values, int len)
{

int i, cnt;
Array __gc *managed_values;
mcDotNetClass __gc *DotNetObject;

managed_values = Array::CreateInstance(__typeof(System::Int32),len);
cnt = managed_values->GetLength(0);


for (i=0;i < cnt;i++) {
managed_values->SetValue(__box(values), i);
}

DotNetObject = new mcDotNetClass;

return DotNetObject->test_array(managed_values);
}

}
 
I have gone through the samples. I haven't been able to get it work using those examples. My c isn't great. I believe the problem is in the C.

Well the key to calling any DLL function is:
1) Getting the call right. You might double-check what variables and order you are using within the COBOL.
__declspec(dllexport) int bint(int input) - this should equate to CALL BINT USING INPUT. then picking up the return value using PROGRAM-STATUS. INPUT should be PIC S9(9) COMP-5. I don't know much about how string functions would return, but that should be a start.

2) Getting the linkage right. Stdcall linkage is pretty standard for windows system DLLs, but a number of other things can be used. If the calls are defined rightly in the COBOL, I would try changing the linkage parm in the COBOL ("WITH C LINKAGE").
 
The standard linkage for Fujitsu CALLs does not work for C programs. You must use the WITH C LINKAGE phrase.
 
I am using the C linkage command. Do any of you know if there is something special that has be done when I am compiling and linking my C dll?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top