Delphi-PRAXiS
Seite 2 von 3     12 3      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Convert sample from platform SDK to Delphi (https://www.delphipraxis.net/82882-convert-sample-platform-sdk-delphi.html)

Robert Marquardt 21. Dez 2006 15:17

Re: Convert sample from platform SDK to Delphi
 
Try WideString. The Delphi WideString is in fact the Windows BSTR used in COM interfaces.
The added conversion is correct. "&&" is "logical and" and "&" is "bitwise and". Delphi uses "and" for both.
"!" is the "logical not" so "= 0" is also correct.

Remko 21. Dez 2006 15:44

Re: Convert sample from platform SDK to Delphi
 
How about this one?
Code:
CComPtr<IADs> m_spADObject;
I made this:
Delphi-Quellcode:
    m_spADObject: IADS;
and one more:
Code:
dwBytes += (sbstrADsPath.Length() + 1) * sizeof(WCHAR);
Delphi-Quellcode:
dwBytes := (length(sbstrADspath) + 1) * SizeOf(WChar); // Or use Inc here as Olli suggests?

ste_ett 21. Dez 2006 15:47

Re: Convert sample from platform SDK to Delphi
 
Zitat:

Zitat von Remko
Code:
dwBytes += (sbstrADsPath.Length() + 1) * sizeof(WCHAR);
Delphi-Quellcode:
dwBytes := (length(sbstrADspath) + 1) * SizeOf(WChar); // Or use Inc here as Olli suggests?

Must be
Delphi-Quellcode:
dwBytes := dwBytes + ((length(sbstrADspath) + 1) * SizeOf(WChar));
otherwise you get a false value. :)

Delphi-Quellcode:
Inc(dwBytes, (length(sbstrADspath) + 1) * SizeOf(WChar));
is possbile also.

Remko 21. Dez 2006 16:08

Re: Convert sample from platform SDK to Delphi
 
From JwaAdsTLB:
Delphi-Quellcode:
// *********************************************************************//
// Interface: IADs
// Flags:    (4416) Dual OleAutomation Dispatchable
// GUID:     {FD8256D0-FD15-11CE-ABC4-02608C9E7553}
// *********************************************************************//
  IADs = interface(IDispatch)
    ['{FD8256D0-FD15-11CE-ABC4-02608C9E7553}']
    function Get_Name: WideString; safecall;
    function Get_Class_: WideString; safecall;
    function Get_GUID: WideString; safecall;
    function Get_ADsPath: WideString; safecall;
    function Get_Parent: WideString; safecall;
    function Get_Schema: WideString; safecall;
    procedure GetInfo; safecall;
    procedure SetInfo; safecall;
    function Get(const bstrName: WideString): OleVariant; safecall;
    procedure Put(const bstrName: WideString; vProp: OleVariant); safecall;
    function GetEx(const bstrName: WideString): OleVariant; safecall;
    procedure PutEx(lnControlCode: Integer; const bstrName: WideString; vProp: OleVariant); safecall;
    procedure GetInfoEx(vProperties: OleVariant; lnReserved: Integer); safecall;
    property Name: WideString read Get_Name;
    property Class_: WideString read Get_Class_;
    property GUID: WideString read Get_GUID;
    property ADsPath: WideString read Get_ADsPath;
    property Parent: WideString read Get_Parent;
    property Schema: WideString read Get_Schema;
  end;
In the sample:
Code:
hr = m_spADObject->get_ADsPath(&sbstrADsPath);
I could use:
Delphi-Quellcode:
sbstrADspath := m_spADObject.get_ADsPath;
but how to get hr?

Robert Marquardt 22. Dez 2006 05:51

Re: Convert sample from platform SDK to Delphi
 
Delphi-Quellcode:
sbstrADspath := m_spADObject.get_ADsPath;
Can be changed to
Delphi-Quellcode:
sbstrADspath := m_spADObject.ADsPath;
The Get_ and Set_ methods are property getters and setters just like in Delphi.
hr you can ignore. This is just COM error return value which is already hidden by the Delphi COM interface.
If really an error arises then your computer is already screwed up completely so no real need to catch it.

Remko 22. Dez 2006 08:54

Re: Convert sample from platform SDK to Delphi
 
Liste der Anhänge anzeigen (Anzahl: 1)
Thanks all, I attached my code so far. I will try to finish and test it today.
Please feel free to comment, improve or correct my code. I'm really learning a lot from this project, especially from all the help on DP!

Remko 22. Dez 2006 11:00

Re: Convert sample from platform SDK to Delphi
 
How to do this one:
Code:
HWND CPropSheetHost::_CreateHiddenWindow()
{
    WNDCLASS wc;

    if(!GetClassInfo(m_hInst, m_szHiddenWindowClass, &wc))
    {
        ZeroMemory(&wc, sizeof(wc));
           
        wc.style         = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc   = (WNDPROC)_HiddenWindowProc;
<cut>

LRESULT CALLBACK CPropSheetHost::_HiddenWindowProc( HWND hWnd,
                                                    UINT uMessage,
                                                    WPARAM wParam,
                                                    LPARAM lParam)
I thought this:
Delphi-Quellcode:
function TPropSheetHost._CreateHiddenWindow: HWND;
var wc: TWndClass;
begin
  if not GetClassInfo(m_hInst, m_szHiddenWindowClass, wc) then
  begin
    ZeroMemory(@wc, SizeOf(wc));
    wc.style         := CS_HREDRAW or CS_VREDRAW;
    wc.lpfnWndProc   := @_HiddenWindowProc;
<cut>

function TPropSheetHost._HiddenWindowProc(hWnd: HWnd; Msg: UINT; WParam: WPARAM; LParam: LPARAM): UINT; stdcall;
But that doesn't make the compiler happy: [Pascal Error] PropSheetHost.pas(174): E2036 Variable required

Edit: Should I make that:
Delphi-Quellcode:
wc.lpfnWndProc   := @TPropSheetHost_HiddenWindowProc;
function TPropSheetHost._HiddenWindowProc(hWnd: HWnd; Msg: UINT; WParam: WPARAM; LParam: LPARAM): UINT; stdcall;
?[/delphi]
or
[delphi][pre]wc.lpfnWndProc := @_HiddenWindowProc;
function _HiddenWindowProc(hWnd: HWnd; Msg: UINT; WParam: WPARAM; LParam: LPARAM): UINT; stdcall;[/pre]?

mkinzler 22. Dez 2006 11:03

Re: Convert sample from platform SDK to Delphi
 
On wich line the error is shown?

Remko 22. Dez 2006 11:10

Re: Convert sample from platform SDK to Delphi
 
wc.lpfnWndProc := @_HiddenWindowProc; (see my edit above)

Remko 22. Dez 2006 11:18

Re: Convert sample from platform SDK to Delphi
 
What's referenced by (LPVOID)this)?
Code:
HWND CPropSheetHost::_CreateHiddenWindow()
{
    WNDCLASS wc;

    if(!GetClassInfo(m_hInst, m_szHiddenWindowClass, &wc))
    {
        ZeroMemory(&wc, sizeof(wc));
           
        wc.style         = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc   = (WNDPROC)_HiddenWindowProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = sizeof(CPropSheetHost*);
        wc.hInstance     = m_hInst;
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
        wc.lpszClassName = m_szHiddenWindowClass;

        if(!RegisterClass(&wc))
        {
            return NULL;
        }
    }

    m_hwndHidden = CreateWindowEx(  0,
                                    m_szHiddenWindowClass,
                                    NULL,
                                    WS_OVERLAPPED |
                                        0,
                                    CW_USEDEFAULT,
                                    CW_USEDEFAULT,
                                    CW_USEDEFAULT,
                                    CW_USEDEFAULT,
                                    NULL,
                                    NULL,
                                    m_hInst,
                                    (LPVOID)this);

    return m_hwndHidden;
}


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:54 Uhr.
Seite 2 von 3     12 3      

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz