?
Solved

Large Buffer Allocation

Posted on 1997-04-18
3
Medium Priority
?
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Author Comment

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

Accepted Solution

by:
gysbert1 earned 400 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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

752 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