Using a c dll with Delphi
|

|
Hi!
From my Delphi program, I would like to use my dll compiled with c, but I
get a runtime error when the function is called.
The parameter is char* c type, that I translate in PChar in Delphi. (I only
have the problem using char*, if I do a similar function using int type in
C, and integer type in Delphi that works)
My dummy function "TextFunction()" should simply return the string passed
into parameter.
///////////////////////// c code : ////////////////////////
char* DLL_EXPORT TextFunction(char* text)
{
return (text);
}
////////////////////////////////////////////////////////////////////////////
///
////////////////////////////// Delphi Code : ///////////////////////////////
Text: TextFunction( text: PChar) : PChar; stdcall;
function LoadDLL: boolean;
function LoadDLL: boolean;
begin
Result := false;
DLLtest := LoadLibrary('testdll.DLL');
if DLLtest 0 then
begin
Result := true; //DLL found
//Get the procedure addresses
@TextFunction:= GetProcAddress(DLLtest, 'TextFunction');
end;
end;
Does anyone see what I am doing wrong |
|
Posted On: Friday 5th of October 2012 12:46:43 AM |
Total Views:
426 |
View Complete with Replies
|
|
RELATED TOPICS OF Delphi Programming PROGRAMMING LANGUAGE
|
|

|
|

|
|

|
I am getting an AV when I compile and run with BPLs. (with BPLs, my app
compiles so much faster--it's 27 megs without BPLs, 10 with). The AV is:
---------------------------
Debugger Fault Notification
---------------------------
Project C:\trak\trak.exe faulted with message: 'access violation at
0x7c937a50: write of address 0x00040f74'. Process Stopped. Use Step or Run
to continue.
---------------------------
OK
---------------------------
Am I correct to lok for modules loaded at the $7c937a50 adress If so, the
closes items are:
I see the list of the DLLs & BPLS that are loaded--the only thing close to
the address is ntdll.dll and Shell32.dll:
Module Load: ntdll.dll. No Debug Info. Base Address: $7C900000. Process
trak.exe (5848)
Module Load: SHELL32.dll. No Debug Info. Base Address: $7C9C0000.
Process trak.exe (5848)
So it would seem that the AV occurs in the ntdll.dll, correct Which doesn't
really tell me much.
My only guess for moving this forward would be to remove BPLs from the list
until the AV is gone, then examine that BPL.
Or is there a better method |

|
VIEWS ON THIS POST
207
|

|
Posted on:
Friday 21st September 2012
|
View Replies!
|
|

|
|

|
My D7 app calls a dll to read memories from a radio. The dll produces a string, and
the length of the string. Calling one function in the dll works fine, but other
functions, using the same parms don't. It's the length that loses it.
procedure TfrmClone.SpeedButtonReadClick(Sender: TObject);
var
i, p: integer;
GetFreq: TGetFreq; //function(s: PChar; var slen: DWORD): LongBool; stdcall;
begin
dllFunc := 'GetFreq';
if ProcHandle 0 then
begin
GetFreq := GetProcAddress(ProcHandle, dllFunc);
if @getFreq nil then
begin
for i := 1 to LoopCtr do
begin
l := 0;
setlength(s,11); // s now contains some random garbage
if GetFreq(pChar(s),l, i) then // s is a global string, l is a global dword
RetFreq := s;
RetMode := GoForMode; // go get mode
..
..
..
end;
function TfrmClone.GoForMode: Shortstring;
var
GetMode: TGetMode; //function(s: PChar; var slen: DWORD): LongBool; stdcall;
begin
result := '';
dllFunc := 'GetMode';
if ProcHandle 0 then
begin
getMode := GetProcAddress(ProcHandle, dllFunc );
if @getMode nil then
begin
l := 0;
if GetMode(pChar(s),l) then
result := s;
end;
end;
end;
=========== In the dll ==============
function GetFreq(s: PChar; var slen: DWORD; chSet: integer): LongBool; stdcall;
//slen is 0
var
fr: string;
begin
result := false;
if chSet > 0 then
dll.SetChannel(chSet);
fr := dll.pollradio;
slen := length(fr); //slen is 7
if length(fr) > 0 then
begin
result := true;
strPLCopy(s, fr, slen);
end;
end;
function GetMode(s: PChar; var slen: DWORD):LongBool; // slen is Inaccessible here
var
mode: string;
begin
result := false;
mode := dll.PollRadio;
slen := length(mode); //AV
if slen > 0 then
begin
result := true;
strPLCopy(s, mode, slen);
end;
end; |

|
VIEWS ON THIS POST
369
|

|
Posted on:
Friday 21st September 2012
|
View Replies!
|
|

|
|

|
I'm trying to convert a string in a, by the user, specified format into a
TDateTime type. However i cannot make it work.
I've attached a code-snippet which illustrates the problem. I'm setting
ShortDateFormat and LongTimeFormat before calling "StrToDateTime". However
it does not care about those My system locale are "dd-mm-yyyy hh:MM:ss"
which i used in this code:
procedure TForm1.Button1Click(Sender: TObject);
begin
ShortDateFormat:='ddmmyy';
LongTimeFormat:='hhMM';
showmessage(DateTimeToStr(StrToDateTime('30-07-2008 13:44:00')));
end;
What makes this even more weird is that the messagebox says it correctly
("300708 1344", just like specified!)
Why does the DateTimeToStr follow ShortDateFormat/LongTimeFormat when the
opposite StrToDateTime does not
Any clues will be helpfull... |

|
VIEWS ON THIS POST
138
|

|
Posted on:
Friday 21st September 2012
|
View Replies!
|
|

|
|

|
|

|
VIEWS ON THIS POST
187
|

|
Posted on:
Friday 21st September 2012
|
View Replies!
|
|

|
|

|
group,
trying to translate a .h file for use within delphi.
How do I translate
typedef void (*GEOSMessageHandler)(const char *fmt, ...);
void initGEOS(GEOSMessageHandler notice_function,GEOSMessageHandler
error_function);
into something useful for Delphi |

|
VIEWS ON THIS POST
358
|

|
Posted on:
Saturday 22nd September 2012
|
View Replies!
|
|

|
|

|
hi there,
some question regarding the use of D2007 RTL on D7
1.is there any worth using D2007 RTL on D7
2.how much the different between D2007 RTL and D7
3.is this mainly about FastCode core (and maybe FastMM), cause i think
D2007 have it while D7 didn't (not integrated by default)
don't ask me if it possible to use D2007 RTL on D7 cause someone has
already tried it (and sucess\t), you can do search on Delphi 7 Lite
(don't ask me where to get it, since it maybe illegal software, except
it's allowed by newsgroup)
here are some text from the readme :
WHAT IS DELPHI 7 LITE
-------------------------
Delphi 7 Lite is a standard installation of Delphi 7 Enterprise in which:
- Applied all the official updates.
- the setup options have been discarded EXCEPT source code.
- Included programming font Consolas (recommended size 10 with ClearType
enabled).
- Editor color settings of Delphi 2006.
- Replace the D7 RTL to D11(Delphi 2007) RTL(FastMM and FastCode Core)
(Optional).
- the setup options have been discarded EXCEPT source code.
- Update 1.1 has been installed (version of the IDE is 7.0.8.1), these
patches are applied:
Update ActionBar to 7.01
- Unneeded files have been removed.
- Can import ActiveX Componets
- Supports MIDAS development.
- Supports CLX Design development.
- Supports IntraWeb 5.0 development.
- Supports RaveReport 5 development.
- Installation do not copy of any files to system directory.
- Green Edition Integrated,you can copy the entire delphi directory to
other place directly ,run file D7LiteReg***.exe to register easily.
- Dynamic Compile after Installation to generate RTL/VCL and other
components .DCU Files,thus minish size of the installation file.
...... and so on
PS: D2007 = Delphi 2007, D7 = Delphi 7
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ |

|
VIEWS ON THIS POST
203
|

|
Posted on:
Saturday 22nd September 2012
|
View Replies!
|
|

|
|

|
hi there,
i'm new here so i do not know exactly where to post, i have some problem
with Angus Johnson TFileSearch component (http://angusj.com/delphi/).
there was a method to find first and next cursor pos (using
TFileSearch.FindFirst and TFileSearch.FindNext property) but what i want
to do is find first pos in file (this was done using FindFirst) and last
pos in file, something like FindLast property that didn't exist.
i try some trick's, to achieve that function
1. using FindNext tricks
{declare procedure and var here}
begin
FileSearch1.Pattern := '300608T'; //this was pattern i set, mean
30/06/2008, T refer it to "Time" (Date through)
iLast := FileSearch1.FindFirst;
while iLast POSITION_EOF do
iLast := FilePos(sFileName); //i hope this will return last position but
it was not
Reset(Fn); //open file
Seek(Fn, iLast);
end;
2. using FindFirst on next pattern
{declare procedure and var here}
begin
DateTime1.Date := 30/06/08; //TDateTime
FileSearch1.Pattern := DateToStr(DateTime1.Date + 1) + 'T'; //this was
tricky pattern i set, mean 30/06/2008 + 1 = 01/07/2008, T refer it to
"Time" (Date through)
iLast := FileSearch1.FindFirst; //this will return first position of
01/07/2008
Reset(Fn); //open file
Seek(Fn, iLast);
{read data, validation, post db, etc}
end;
the problem was partially solved using 2nd trick, but how about if
01/07/2008 (010708T) never found in file it will return file pos = -1,
and will give I/O error (negative seek), sure i can use condition to check
if pos = -1 then loop until end file, but it really pain, since -1 mean
also "Data Not Found in File".
regards,
deli soetiawan
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ |

|
VIEWS ON THIS POST
291
|

|
Posted on:
Monday 24th September 2012
|
View Replies!
|
|

|
|

|
Hi all,
I'm out hunting for bzip2.dll for use with Delphi classes (DI or Jcl
Decompressors), but can't find a recent version ready compiled for Win32
Although google gives many hits on "bzip2.dll" but I don't trust
clicking any of those cheap .dll mouse traps which is now littering the
entire Internet.
Latest source (1.0.5 as of mars 2008) is available from here, http://www.bzip.org/downloads.html
Perhaps can anyone compile it for me (or give a hint about a secure
link for download).
Anyone |

|
VIEWS ON THIS POST
443
|

|
Posted on:
Monday 24th September 2012
|
View Replies!
|
|

|
|

|
I am trying to send a Fax using APRO components but the conversion from
BMP to APF format is not very good. I am using the demo app to convert a
bmp to APF file. I have tried all the combination available in the options.
Is it possible to get this conversion to work properly or should I look
for some other components. |

|
VIEWS ON THIS POST
191
|

|
Posted on:
Tuesday 25th September 2012
|
View Replies!
|
|

|
|

|
Hi ,
I can't start RAD Studio 2007 this morning. After the splash screen has
been shown and all packages has been loaded, the splash disapears and I
get this error thanksfully trapped by MadExcept :
I can send the full bug report to binaries, I required.
Any ideas
main thread ($c70):
1b8efe5e +000 ieframe.dll
7c91eae0 +010 ntdll.dll
KiUserCallbackDispatcher
7e39fc53 +02e USER32.dll CreateWindowExW
201caf2b +043 vcl100.bpl OleCtrls 863 +5
OleCtrls.TOleControl.CreateWnd
2013f80a +016 vcl100.bpl Controls 6883 +3
Controls.TWinControl.CreateHandle
2013fad0 +074 vcl100.bpl Controls 6994 +7
Controls.TWinControl.UpdateShowing
2013fafe +0a2 vcl100.bpl Controls 6997 +10
Controls.TWinControl.UpdateShowing
2013fcb1 +0e5 vcl100.bpl Controls 7041 +21
Controls.TWinControl.UpdateControlState
20142692 +026 vcl100.bpl Controls 8397 +3
Controls.TWinControl.CMVisibleChanged
2013c527 +2bb vcl100.bpl Controls 5146 +83
Controls.TControl.WndProc
201406a7 +4fb vcl100.bpl Controls 7304 +111
Controls.TWinControl.WndProc
20159e7f +553 vcl100.bpl Forms 3512 +136
Forms.TCustomForm.WndProc
2013c1b4 +024 vcl100.bpl Controls 5021 +5
Controls.TControl.Perform
2013ac16 +026 vcl100.bpl Controls 4169 +5
Controls.TControl.SetVisible
201597b6 +03a vcl100.bpl Forms 3316 +8
Forms.TCustomForm.SetVisible
20d1bad4 +324 designide100.bpl DeskForm 492 +74
DeskForm.TDesktopForm.LoadWindowState
0041dc2c +000 bds.exe AppMain 5602 +0
AppMain.TAppBuilder.LoadWindowState
0041262d +005 bds.exe AppMain 1271 +0
AppMain.TBorlandIDE.LoadWindowState
209dd06e +1fa coreide100.bpl Desktop 642 +59
Desktop.LoadDeskState
209dfa7e +036 coreide100.bpl Desktop 1664 +5
Desktop.TDesktopState.Load
209df463 +03b coreide100.bpl Desktop 1496 +4
Desktop.TDesktopStates.LoadDesktop
20a5d95c +138 coreide100.bpl DocModul 786 +35
DocModul.TFilterList.OpenFile
20a615b7 +04f coreide100.bpl DocModul 2514 +3
DocModul.CallDefaultOpenProc
209de6ad +421 coreide100.bpl Desktop 1088 +81 Desktop.LoadDesktop
0041399c +170 bds.exe AppMain 1885 +51
AppMain.TAppBuilder.CMPostCreateInit
2013c527 +2bb vcl100.bpl Controls 5146 +83
Controls.TControl.WndProc
201406a7 +4fb vcl100.bpl Controls 7304 +111
Controls.TWinControl.WndProc
20159e7f +553 vcl100.bpl Forms 3512 +136
Forms.TCustomForm.WndProc
2013fdd0 +02c vcl100.bpl Controls 7073 +3
Controls.TWinControl.MainWndProc
20040e4c +014 rtl100.bpl Classes 11583 +8 Classes.StdWndProc
7e3996c2 +00a USER32.dll DispatchMessageA
201625f0 +0fc vcl100.bpl Forms 8105 +23
Forms.TApplication.ProcessMessage
2016262a +00a vcl100.bpl Forms 8124 +1
Forms.TApplication.HandleMessage
2016291f +0b3 vcl100.bpl Forms 8223 +20
Forms.TApplication.Run
--
Pierre Y. |

|
VIEWS ON THIS POST
377
|

|
Posted on:
Wednesday 26th September 2012
|
View Replies!
|
|

|
|

|
Is it possible to create GUID strings programmatically in Delphi 7
If so, how
I can't find anything in the Delphi help system....
I need to create unique file names for a file caching function and I
thought that a GUID could be used, since it is unique each time.
But if some other method can be used instead, please tell me.
What I need is a function that can create a unique but not overly long
string to be used as a file name in a caching directory.
I need to either be able to decode the original file name from the
string or keep records somewhere of the connection between file name
and string.
/BoB |

|
VIEWS ON THIS POST
149
|

|
Posted on:
Wednesday 26th September 2012
|
View Replies!
|
|

|
|

|
Windows Mail could not post your message. Subject '"Richedit line insertion
error"', Account: 'newsgroups.codegear.com', Server:
'newsgroups.codegear.com', Protocol: NNTP, Server Response: '480 you do not
have posting access to {borland.public.delphi.vcl.components.using}', Port:
119, Secure(SSL): No, Server Error: 480, Error Number: 0x800CCCA9
What is the problem here |

|
VIEWS ON THIS POST
222
|

|
Posted on:
Thursday 27th September 2012
|
View Replies!
|
|

|
|

|
I am working on a class to implement data retrievel over the Internet.
When the data are retrieved there will be a rather long time before it
is done and I would like to create events inside the class to make it
possible in the host application to show progress information and
maybe also some messages.
I know how to make event properties in a class and how to check if it
has been assigned and if so call the method.
But this may break the communications function if the host application
is not well behaved and exits the function quickly. If this happens
(for example if the host starts to do some lengthy operation in the
event code) then the data transfer will be put on hold.
So I ask myself if it could be solved with threads instead But I
don't know the answer so I ask here.
Basically I have something like this:
type
TMyMessageEvent = procedure(Sender: TObject; Msg: string) of object;
TNyCommObject = class
private
FOnSomeEvent: TMyMessageEvent;
....
public
...
property OnSomeEvent: TMyMessageEvent read FOnSomeEvent write
FOnSomeEvent;
end;
procedure TMyCommObject.HandleData;
begin
{Retrieve the data in a long loop}
{in the loop on some condition fire off event}
if MyCondition and Assigned(FOnSomeEvent) then
FOnSomeEvent(Self, 'Something happened');
end;
Here I would like to *not* call the event procedure in the host
application directly but instead create a thread that executes the
code while the main object code can continue processing the data.
What would be the best approach for such a solution
If possible a code example is appeciated.
--
Bo Berglund |

|
VIEWS ON THIS POST
226
|

|
Posted on:
Thursday 27th September 2012
|
View Replies!
|
|

|
|

|
when trying to debug a specific COM dll the IDE crash, or i get only the
CPU Debug video or it just get stuck.. other COM Dll's debugging works fine,
fellow workers doesn't have problems with debugging that DLL as well but on
my computer it keeps crashing...
any ideas
tnx, roi. |

|
VIEWS ON THIS POST
437
|

|
Posted on:
Friday 28th September 2012
|
View Replies!
|
|

|
|

|
Suddenly today my D7(with all available updates) started AVing every few seconds in
dcc70.dll when editing. When it happens, the unit being edited becomes read only(but
not on disk). Also I get an AV on closing Delphi. Restarting Delphi has no effect.
I did a repair install, which ran so quickly, I don't believe it did anything.
2 things changed on the box yesterday, I don't know how to determine if either is a
cause.
I installed SP3 for Windows XP, and tried unsuccessfully to install Mike Lischke's
TThemeManager component(paraphrasing here - unit already compiled, then themes unit
compiled with a different version).
I have a couple of MadExcept logs I can put on attachments, if they're of any use.
There seems to be a lot on the web about this dll, but I didn't find a real fix. I
hope there is one, because this install is unusable. |

|
VIEWS ON THIS POST
375
|

|
Posted on:
Saturday 29th September 2012
|
View Replies!
|
|

|
|

|
I am using BDS 2006 Architect and am experiencing memory errors that are popping up while I am editing code. What seems to be happening is tha BDS 2006 is having memory leaks while one is editing and compiling. This cam be monitored with the Win Task Manager Processes. Eventually, the bds.exe process gobbles up enough memory where it starts to cause error dialogs to pop-up while one is editing code. Has anyone seen this Is there a Fix I have already applied the 2nd Updates patch, but no difference. Matt |

|
VIEWS ON THIS POST
205
|

|
Posted on:
Sunday 30th September 2012
|
View Replies!
|
|

|
|

|
I am invoking a horizontal band using bho in windows explorer while
starting up
I tried the following, but it doesnt invoke, results in an error
"Invalid variant operation", the code is in delphi.
Following is the code snippet
IE := pUnkSite as IWebbrowser2;
if Assigned(IE) and (InitialiseShellType = stWindowsExplorer) then
begin
BandId.vt := VT_BSTR;
BandId.bstrVal := '{CC546B07-8E2E-4D7B-AAF6-BDDBFDD738F5}';
vtShow.vt := VT_BOOL;
vtShow.boolVal := True;
vtSize.vt := VT_INT;
vtSize.IntVal := 0;
IE.ShowBrowserBar(BandId,vtShow,vtSize);
IE := Nil;
end;
From some other newsgroup, I gathered that there might be something wrong
with boolval := True,
which I am not very sure.
I would appreciate if any one could shed some light on solving this |

|
VIEWS ON THIS POST
221
|

|
Posted on:
Wednesday 3rd October 2012
|
View Replies!
|
|

|
|

|
Maybe this is just me, but I'm finding it incredibly confusing and heavy
going to install and update my Delphi 2007 for Win 32.
I've just built a new computer and am reinstalling everything. Of all the
apps I've got, Delphi takes the biscuit for being the most confusing to
bring up to date.
Just follow me through, here, and tell me if it's me being thick, or
CodeGear being unhelpful, would you
I've got Delphi installed and the Version number in Help | About is
11.0.2804.9245. I want to know if this is up to date or not. So I go to
the Registered User Downloads page and find a mass of confusion. For
instance, I spot an ISO called 'Delphi 2007 for Win32 R2/Update 3 ISO'.
My first thought is "What the heck's R2". Presumably it's a later version
of the product I bought (back in Feb 07). It also mentions Update 3. But
that's confusing, because listed above it are 'Delphi 2007 for Win32/Update
3' as a zip or autoinstaller. So does it mean R2 includes Update 3 And do
I want Update 3, or the full blown R2/Update 3 In fact, are there two
different Update 3s One for the original Delphi 2007, and one for Delphi
2007 R2
So as well as having a product name - Delphi 2007 - we also have Release
numbers and Update numbers, which seems one too many to me. Anyway.......
......there are three links mentioning Update 3. My question is, do I need
it So I follow one of the links to find...... no pre-requisites
mentioned!! It does not say what Version number it applies to, nor what the
new Version number will be after installing it. UNBELIEVABLE.
Not to worry, let's look a bit higher up the list.......
......and I see that the Updates suddenly get months instead of numbers!!
And then, as my eyes wanders ever upwards I find, astonishingly, that as
well as Release numbers, Update numbers and Update months, we've now got
Hotfixes as well!!! To top it all, none of these seem to appear in the Help
| About box in Delphi, which just seems to show a four-field Version number,
giving us:
Release Numbers
Update Numbers
Update Months
Hotfixes
Version numbers (in the application)
......and no obvious correlation between them.
This is just unbelievable. Why on earth can't Codegear just do what most
other vendors do and stick to version numbers throughout, viz:
11.0, 11.1, 11.2, etc. Simple.
Yes, I know they increment the third and fourth digit fields in the version
number in the Help About box, but nowhere on the Registered User Downloads
page do they tell you which digits relate to which Release Numbers, Update
Numbers, Update Months or Hotfixes.
Honestly, CodeGear, this is just hopeless. NO OTHER PRODUCT (and I use
plenty) has such a confusing system of updates, patches, hotfixes and
upgrades as Delphi. Furthermore, if I updated any of my own software like
this, I'd be lynched by my users!
I'm still only moderately confident about how to proceed, but as far as I
can glean, it's:
1/ Original product
2/ Update 3
3/ December 07 Update
4/ April 08 Hotfix
5/ Help Update 3
Does that seem right
Is there any chance at all of CodeGear getting a grasp on this situation
SteveT
PS: I've just spotted something else, which I almost couldn't believe.
CodeGear releases these "Updates", but tells you to run "setup.exe
/upgrade". Yes, "upgrade", not "update"! |

|
VIEWS ON THIS POST
194
|

|
Posted on:
Wednesday 3rd October 2012
|
View Replies!
|
|

|
|

|
A few days ago I noticed that I quit getting debug info when I put a break
point on a variable, stop during runtime and hold the cursor over the
variable. Nothing happens. I am not even told it was optimized.
Can someone help me , Larry Killen wrote:
> Actually, when I hold the cursor over a variable, it flickers as if
> it is trying to retrieve a value.
>
> I think something is screwed up.
If you are sure the appropriate checkbox in the Tools->Options dialog
(under Code Insight) is checked then it looks like your system has
gotten into a state where hint windows are not displayed on top of the
window they belong to but beneath it. I have seen that even for the
popup hints of the Windows taskbar buttons, so it's not Delphi
specific. A reboot of the machine fixes it, at least for a time.
--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives : http://www.tamaracka.com/search.htm http://groups.google.com |

|
VIEWS ON THIS POST
228
|

|
Posted on:
Wednesday 3rd October 2012
|
View Replies!
|
|

|
|

|
I have a dual processor AMD 4400 and I noticed the machine was running
kind of slow. The task manager shows BDS.Exe using 50% of the processors
(100% of 1 processor). My compiled program is not running. Nothing is
running on the machine, yet the IDE takes 100% of one of the CPU's for
several hours even though the IDE is just sitting there doing nothing.
Exiting Delphi and restarting it and it loads my application and after a
few seconds it is down to 0 CPU cycles (which is what I expect). Then I
run my application within the IDE and exit the program so it returns to
the IDE, and it behaves fine with 0 CPU cycles.
So why does it at times hog all the CPU Is it doing my taxes in the
background Decoding signals from SETI Calculating Pi to the last
decimal place I can understand if the Delphi IDE uses 100% CPU for a
few seconds, but for a few hours when there is nothing else running
What's up with that
Sam |

|
VIEWS ON THIS POST
232
|

|
Posted on:
Thursday 4th October 2012
|
View Replies!
|
|

|
|