AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Convert sample from platform SDK to Delphi
Thema durchsuchen
Ansicht
Themen-Optionen

Convert sample from platform SDK to Delphi

Offene Frage von "Remko"
Ein Thema von Remko · begonnen am 21. Dez 2006 · letzter Beitrag vom 27. Dez 2006
Antwort Antwort
Seite 3 von 3     123   
Benutzerbild von ste_ett
ste_ett

Registriert seit: 10. Sep 2004
Ort: Dülmen
464 Beiträge
 
Delphi 7 Professional
 
#21

Re: Convert sample from platform SDK to Delphi

  Alt 22. Dez 2006, 12:26
"this" is a pointer to the current instance of the class.

"(LPVOID)" turns the pointer from a pointer to a class into a normal pointer.
Stefan
"Geht nicht!" ist keine Fehlerbeschreibung und "Hab ich schon versucht!" keine Antwort!

Hey, it compiles! Ship it!
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#22

Re: Convert sample from platform SDK to Delphi

  Alt 22. Dez 2006, 12:59
Not sure I understand what you mean. Can you show me the Delphi translation?
  Mit Zitat antworten Zitat
Benutzerbild von ste_ett
ste_ett

Registriert seit: 10. Sep 2004
Ort: Dülmen
464 Beiträge
 
Delphi 7 Professional
 
#23

Re: Convert sample from platform SDK to Delphi

  Alt 22. Dez 2006, 13:07
Delphi-Quellcode:

m_hwndHidden := CreateWindowEx( ...,
                            ...,


                                Self);
Stefan
"Geht nicht!" ist keine Fehlerbeschreibung und "Hab ich schon versucht!" keine Antwort!

Hey, it compiles! Ship it!
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#24

Re: Convert sample from platform SDK to Delphi

  Alt 22. Dez 2006, 13:10
Thanks Stefan, you confirm what I made of it. On to the next one
  Mit Zitat antworten Zitat
Robert Marquardt
(Gast)

n/a Beiträge
 
#25

Re: Convert sample from platform SDK to Delphi

  Alt 22. Dez 2006, 13:14
The conversion of "(LPVOID) this" is "Pointer(Self)". _HiddenWindowProc receives a WM_CREATE message where the LParam points to a CREATESTRUCT structure. The lpCreateParams element of that structure is the value handed to CreateWindowEx. This allows to jump back into object land inside of _HiddenWindowProc function by casting the pointer back and then having access to the object again.
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#26

Re: Convert sample from platform SDK to Delphi

  Alt 22. Dez 2006, 13:24
Thanks Robert, that makes it clear. (I understand now that I didn't take the most easy example to start with for a first conversion, but I'm learning not also the conversion itself but a lot more! But hey, I guess it's Luctor et Emergo!)
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#27

Re: Convert sample from platform SDK to Delphi

  Alt 22. Dez 2006, 14:00
Just posting some progress (attached). I'm currently stuck at _HiddenWindowProc()
Code:
   CPropSheetHost *pThis = (CPropSheetHost*)((LONG_PTR)GetWindowLongPtr(hWnd, VIEW_POINTER_OFFSET));

    switch (uMessage)
    {
    case WM_NCCREATE:
        {
            LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
            pThis = (CPropSheetHost*)(lpcs->lpCreateParams);
            ::SetWindowLongPtr(hWnd, VIEW_POINTER_OFFSET, (LONG)(LONG_PTR)pThis);
I'm going to stop for the moment, I was obviously too optimistic I'd be able to finish it today. Fröhliche Weihnachten und ein glückliches Neues Jahr to everyone here.
Angehängte Dateien
Dateityp: pas propsheethost_202.pas (14,9 KB, 7x aufgerufen)
  Mit Zitat antworten Zitat
Robert Marquardt
(Gast)

n/a Beiträge
 
#28

Re: Convert sample from platform SDK to Delphi

  Alt 22. Dez 2006, 14:17
Code:
   CPropSheetHost *pThis = (CPropSheetHost*)((LONG_PTR)GetWindowLongPtr(hWnd, VIEW_POINTER_OFFSET));
This is a local variable which is immediately initialized. GetWindowLongPtr supersedes GetWindowLong. You can use GetWindowLong instead.
The value pulled is the this or Self value handed in as parameter to CreateWindowEx.
Code:
    switch (uMessage)
    {
    case WM_NCCREATE:
        {
            LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
            pThis = (CPropSheetHost*)(lpcs->lpCreateParams);
            ::SetWindowLongPtr(hWnd, VIEW_POINTER_OFFSET, (LONG)(LONG_PTR)pThis);
Now here the value is extracted from the CREATESTRUCT structure and stuffed into the extra data area of the window.
This works because WM_NCCREATE is about the first message received so the above variable initialization almost always pulls the value.
It just fails for WM_NCCREATE itself where it gets an uninitialized value, but in this case the variable is initialized from the CREATESTRUCT.
It is a bit overcoded and it contains a bug. The code is not 64 bit safe. (LONG)(LONG_PTR) is a double typecast which first casts the pointer to the type LONG_PTR. LONG_PTR can hold a 64 bit value. Unfortunately it is then casted to LONG which can hold only 32 bits. So the second typecast is actually a bug.

So this is just a trick to be always able to return to object land each time _HiddenWindowProc is called with a message.
Delphi-Quellcode:
var
  Form: TForm1; // or whatever type you have handed in to CreateWindowEx
begin
  Form := GetWindowLong(hWnd, VIEW_POINTER_OFFSET));
  case Msg of
    WM_NCCREATE:
      SetWindowLong(hWnd, VIEW_POINTER_OFFSET, LONG(LPCREATESTRUCT(lParam).lpCreateParams));
This is the trick in Delphi. You can of course drop all this and just access the global variable Form1 Delphi has created for you already.
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#29

Re: Convert sample from platform SDK to Delphi

  Alt 27. Dez 2006, 11:17
OK, so:
Code:
LRESULT CALLBACK CPropSheetHost::_HiddenWindowProc( HWND hWnd,
                                                    UINT uMessage,
                                                    WPARAM wParam,
                                                    LPARAM lParam)
{
    CPropSheetHost *pThis = (CPropSheetHost*)((LONG_PTR)GetWindowLongPtr(hWnd, VIEW_POINTER_OFFSET));

    switch (uMessage)
    {
    case WM_NCCREATE:
        {
            LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
            pThis = (CPropSheetHost*)(lpcs->lpCreateParams);
            ::SetWindowLongPtr(hWnd, VIEW_POINTER_OFFSET, (LONG)(LONG_PTR)pThis);
        }
        break;

    case WM_CREATE:
        break;

    case WM_DESTROY:
        break;

    case WM_ADSPROP_NOTIFY_CHANGE:
        OutputDebugString(TEXT("WM_ADSPROP_NOTIFY_CHANGE\n"));
        break;

    case WM_DSA_SHEET_CREATE_NOTIFY:
        {
            PDSA_SEC_PAGE_INFO pSecPageInfo;
           
            // Extract the secondary sheet information from the wParam.
            if(S_OK == pThis->_ExtractSecPageInfo(wParam, &pSecPageInfo))
            {
                // Create a secondary property sheet.
                pThis->_CreateSecondaryPropertySheet(pSecPageInfo);
            }
            else
            {
                // Even if the extraction failed, the wParam needs to be freed.
                pSecPageInfo = (PDSA_SEC_PAGE_INFO)wParam;
            }

            /*
            The receiver of the message must free the DSA_SEC_PAGE_INFO
            structure when it is no longer needed.
            */
            LocalFree(pSecPageInfo);
        }
        return 0;

    case WM_DSA_SHEET_CLOSE_NOTIFY:
        if(PROP_SHEET_HOST_ID == wParam)
        {
            OutputDebugString(TEXT("PROP_SHEET_HOST_ID\n"));
        }
        return 0;

    default:
        break;
    }

    return DefWindowProc(hWnd, uMessage, wParam, lParam);
}
Delphi-Quellcode:
function TPropSheetHost._HiddenWindowProc(hWnd: HWnd; Msg: UINT; WParam: WPARAM; LParam: LPARAM): UINT; stdcall;
var lpcs: TCreateStruct;
  PropSheetHost: TPropSheetHost;
  pSecPageInfo: PDSA_SEC_PAGE_INFO;
  begin
  PropSheetHost := TPropSheetHost(GetWindowLong(hWnd, VIEW_POINTER_OFFSET));
  case Msg of
    WM_NCCREATE: SetWindowLong(hWnd, VIEW_POINTER_OFFSET, LONG(LPCREATESTRUCT(lParam).lpCreateParams));
    WM_CREATE:;
    WM_DESTROY:;
    WM_ADSPROP_NOTIFY_CHANGE: OutputDebugString('WM_ADSPROP_NOTIFY_CHANGE'#10#13);
    WM_DSA_SHEET_CREATE_NOTIFY:
    begin
      // Extract the secondary sheet information from the wParam.
      if _ExtractSecPageInfo(wParam, pSecPageInfo) = S_OK then
      begin
        // Create a secondary property sheet.
        _CreateSecondaryPropertySheet(pSecPageInfo);
      end
      else begin
        // Even if the extraction failed, the wParam needs to be freed.
        pSecPageInfo := PDSA_SEC_PAGE_INFO(wParam);
      end;
      {*
      The receiver of the  message must free the DSA_SEC_PAGE_INFO
      structure when it is no longer needed.
      *}

      LocalFree(Cardinal(pSecPageInfo));
      Result := 0;
      Exit;
    end;
    WM_DSA_SHEET_CLOSE_NOTIFY:
    begin
      if PROP_SHEET_HOST_ID = wParam then
      begin
        OutputDebugString('PROP_SHEET_HOST_ID'#10#13);
      end;
      Result := 0;
    end;
  end;
  Result := DefWindowProc(hWnd, Msg, wParam, lParam);
end;
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#30

Re: Convert sample from platform SDK to Delphi

  Alt 27. Dez 2006, 12:02
Is this translation correct?

Code:
HRESULT CPropSheetHost::_AddPagesForObject(IADs *padsObject)
{
    HRESULT hr;
   
    // Get a copy of our IDataObject.
    CComPtr<IDataObject> spDataObject;
    hr = this->QueryInterface(IID_IDataObject, (LPVOID*)&spDataObject);
    if(FAILED(hr))
    {
        return hr;
    }
    < CUT >
Delphi-Quellcode:
function TPropSheetHost._AddPagesForObject(hPage: HPROPSHEETPAGE; lParam: LPARAM): HRESULT;
var hr: HResult;
 spDataObject: IDataObject;

begin
  // Get a copy of our IDataObject.
  spDataObject := CreateComObject(IID_IDataObject) as IDataObject;
  hr := QueryInterface(IID_IDataObject, spDataObject);
  if Failed(hr) then
  begin
    Result := hr;
    Exit;
  end;
    < CUT >
Some other questions:
How to cast a WideString to PAnsiChar? //Edit: PAnsiChar := PChar(String(WideString));

Code:
    // Fill out the PROPSHEETHEADER structure.
    psh.dwSize          = sizeof(PROPSHEETHEADER);
    psh.dwFlags         = PSH_DEFAULT;
    psh.hwndParent      = m_hwndParent;
    psh.hInstance       = NULL;
    psh.pszIcon         = NULL;
    psh.pszCaption      = W2T(sbstrTemp);
    psh.nPages          = (UINT)m_rgPageHandles.GetSize();
    psh.phpage          = m_rgPageHandles.GetData();
    psh.pfnCallback     = NULL;
GetSize returns number of elements in array? --> psh.nPages := Length(m_rgPageHandles.GetSize)?
Getdata stores all members in a pointer? How to do this in Delphi? psh.u3.phpage := @m_rgPageHandles;?

Edit: adding one more question, how to convert this:
Code:
            LPBYTE pDest = (LPBYTE)*ppSecPageInfo;
            LPBYTE pSource = (LPBYTE)wParam;

            // Copy the original memory to the new block.
            CopyMemory(pDest + dwOffset, pSource, sizeOldSize);
This part CopyMemory(pDest + dwOffset will not work in Delphi. // EDIT: CopyMemory(PChar(pDest) + dwOffset, pSource, sizeOldSize); ?

Added code so far as attachment
Angehängte Dateien
Dateityp: pas propsheethost_116.pas (21,2 KB, 28x aufgerufen)
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 3 von 3     123   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:24 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz