Solved

Large Buffer Allocation

Posted on 1997-04-18
3
252 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 68
find a node in VST 2 73
Not able to call Delphi XE10 dll function from Delphi 6.0 4 37
scroll down TListBox component in Delphi 1 19
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

829 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