Solved

Large Buffer Allocation

Posted on 1997-04-18
3
235 Views
Last Modified: 2010-04-04
I am attempting to allocate a large buffer 1.5Meg
in Delphi 1.  (In Windows 3.11)

I need to be able to assign this buffer to a pointer and
pass it to a routine written in C in a DLL. The C routine
is expecting a pointer to be "typedef char huge*" where
huge is "#define HUGE huge", which I understand exceeds
the 64k boundary.

Please give code example in your answer, showing exact
implementation.
0
Comment
Question by:jturpin
  • 2
3 Comments
 
LVL 1

Author Comment

by:jturpin
ID: 1335463
Edited text of question
0
 
LVL 2

Accepted Solution

by:
gysbert1 earned 200 total points
ID: 1335464
The following code Allocates the memory and gives you the pointer you requested.

procedure TForm1.Button1Click(Sender: TObject);
var
      MyHandle  : THandle;
      MyPointer : Pointer;
begin
      MyHandle:=GlobalAlloc(GMEM_FIXED or GMEM_SHARE,1500000);
      MyPointer:=GlobalLock(MyHandle);
        { Do Your Stuff to the code }
      Messagebeep(word(-1));
        MyCFunctionInDll(MyPointer);
        { Remember to DeAllocate later !!}              GlobalUnlock(MyHandle);
      GlobalFree(MyHandle);
end;

Remember that it is better to use the THandle directly in windows. The memory has to be fixed (in the flags) in order to prevent windows from moving it about at leasure.

If you do not know how to do the passing of the pointer to the C++ dll using C calling convention, you can feel free to ask that as another question. It should only be about 50 points though!


0
 
LVL 2

Expert Comment

by:gysbert1
ID: 1335465
Oh yes !

The memory functions used are windows API calls. Look them up in the API help for more info. Since C and Delphi shares the same API as interface to windows you can use the functions in your dll as well (presuming you wrote the dll).

PS. It is usually better to use the windows handle rather than a pointer to do this since it is better handled by the API.

Let me know if you still have questions.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now