473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

problem calling Delphi w32 DLL from a Delphi.Net webservice

Hello,

I am attempting to call a (Delphi) win32 DLL from a Delphi.Net webservice. I am using a slightly modified version of the hello world webservice that comes with Delphi 2006.

The DLL works fine when called from a win32 app. The problem I am encountering is that the string being returned to the caller is in Chinese (No, I'm not kidding). (I need it to be in English).

Background: The DLL uses 3 pchar parms, 2 in and one out. In debug mode the ws is passing the 2 string parms in ok (I can see them) but the "string" being returned is all unprintable characters.

I am using the default Cassini server built in to D2006. I "hardcoded" hello world as my return string to rule out anything internal to the DLL, and it still returns 5 chinese characters to my calling web browser. FYI I tried changing the response Encoding in the web.config from utf-8 to both ISO-8859-1 (or whatever) and "Windows-1252" to no avail.

Note the HelloWorld and Add functions both return legible data. I am sure it has something to do with widestrings vs regular strings but I've tried everything I can think of and its still Chinese. I have read every article an tip that Google can find. I am using PChar in the DLL because I dont want to mess with ShareMem.

This is my first time using .Net and I am stuck, so any help would be Greatly Appreciated!

Thanks!


Sample code follows.

The DLL:
===============================================
library testDLL;

uses
SysUtils,
Classes;

function GetData(Name, Email, Answer : PChar) : Integer; stdCall;
var
S: string;
begin
// Note for purposes of this demo I am not doing anything with the input parms
s := 'hello' + 'world';
StrPCopy(Answer,S );
Result := Length(S);
end;

exports GetData;

begin
end.
================================================== ==

The webService code:
===================
unit WebService1;

interface
{$UNSAFECODE ON} // Note I needed this so I can use PChar

uses
System.Collections, System.ComponentModel,
System.Data, System.Diagnostics, System.Web,
System.Web.Services;

function GetData(Name, Email, Answer: PChar) : Integer; StdCall; External 'testDLL.dll'; unsafe;
type
TWebService1 = class(System.Web.Services.WebService)
{$REGION 'Designer Managed Code'}
strict private
components: IContainer;
procedure InitializeComponent;
{$ENDREGION}
strict protected
procedure Dispose(disposing: boolean); override;
private
{ Private Declarations }
public
constructor Create;
// Sample Web Service Method
[WebMethod]
function HelloWorld: string;
[WebMethod]
function Add(A, B: Integer): Integer;
[WebMethod]
function GetKey(Name, Email : String) : String;

end;

var
c : integer;

implementation

{$REGION 'Designer Managed Code'}
procedure TWebService1.InitializeComponent;
begin

end;
{$ENDREGION}

constructor TWebService1.Create;
begin
inherited;
InitializeComponent;
end;

procedure TWebService1.Dispose(disposing: boolean);
begin
if disposing and (components <> nil) then
components.Dispose;
inherited Dispose(disposing);
end;

// Sample Web Service Method
// The following method is provided to allow for testing a new web service.

function TWebService1.HelloWorld: string;
begin
Result := 'Hello World';
end;

function TWebService1.Add(A, B: Integer): Integer;
begin
Result := A + B;
end;

function TWebService1.GetKey(Name, Email: String): String; unsafe;
var N, E, X : PChar;
R : Array[0..250] of char;
S : String;
i, ctr : Integer;
begin
N := @Name;
E := @Email;
ctr := GetData(@Name, @Email, @R);
i := 0;
While R[i] <> #0 do begin // had to do it this way because
S := S+R[i]; // no typecasting or conversion routines worked.
i := i + 1;
end;

Result := S;
end;


end.
Sep 26 '08 #1
0 1712

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Programatix | last post by:
Hi, I'm working on a project which includes WebServices and Windows Form application. The Windows Form application will call the WebServices to retrieve data from database. The data will be...
2
by: Programatix | last post by:
Hi, I'm working on a project which includes WebServices and Windows Form application. The Windows Form application will call the WebServices to retrieve data from database. The data will be...
0
by: Raed Sawalha | last post by:
Dear: I'm working web application that expect to pass an class object to DLL(Class Lib) I just Attached the DLL File into Web Solution ( DLL is located in other machine), inside the class...
3
by: Merav Orion via .NET 247 | last post by:
I have a problem calling webservice from client side javascript. The javascript call the settimeout() method. when the user press submit button it ignore the press and keep refreshing the page. it...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
3
by: Dan | last post by:
Hi all, I have a DLL built in Delphi 7 that has a few functions for extracting data from some b-tree database tables. Everything works great when called by a test app written in Delphi, yet...
3
by: cinias | last post by:
Hi, I'm writing application for Windows CE 5.0. in C#. My app is using WebService which I wrote in Delphi 2006. When I start app I want to read URL to my WebService from XML file. Problem is...
7
by: Ryanivanka | last post by:
hi, I am using a delphi DLL in vc++,static linked with ".h"and "lib". the export functions in DLL are "__stdcall",but the function doesn't work well,it often returns some weird values. when I add...
5
by: kelvin.koogan | last post by:
How can I call a function in a Delphi DLL from C++/CLI? The Delphi function is declared as follows: function Func1(IsDsb: Boolean; FirstStr, SecondStr : String): String; I've tried ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.