Solved

Large Buffer Allocation

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 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