Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Large Buffer Allocation

Posted on 1997-04-18
3
Medium Priority
?
272 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

610 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