compile error. TO : Antonio.

compile error. TO : Antonio.

Postby yunbg1 » Mon Jul 29, 2013 3:51 am

Hi Antonio.

This source compile error ?



//
BCC5.82 + FW10.2 + HARBOUR 1.1 Build.


Compile Erroer comment.

Error E2140 test.prg 48: Declaration is not allowed here in function HB_FUN_EXE_TEST
Error E2140 test.prg 49: Declaration is not allowed here in function HB_FUN_EXE_TEST

Code: Select all  Expand view

//------------------------------------------------
FUNC Main()

test("test.ppp")

RETU NIL

#pragma BEGINDUMP

#define _UNICODE 1
#define UNICODE 1

#pragma comment (lib, "wintrust")

HB_FUNC(TEST)
{
    LONG lStatus;
    DWORD dwLastError;

    // Initialize the WINTRUST_FILE_INFO structure.

    WINTRUST_FILE_INFO FileData;

    memset(&FileData, 0, sizeof(FileData));
    FileData.cbStruct = sizeof(WINTRUST_FILE_INFO);
    FileData.pcwszFilePath = hb_parc(1);
    FileData.hFile = NULL;
    FileData.pgKnownSubject = NULL;

    /*

    WVTPolicyGUID specifies the policy to apply on the file
    WINTRUST_ACTION_GENERIC_VERIFY_V2 policy checks:

    1) The certificate used to sign the file chains up to a root
    certificate located in the trusted root certificate store. This
    implies that the identity of the publisher has been verified by
    a certification authority.

    2) In cases where user interface is displayed (which this example
    does not do), WinVerifyTrust will check for whether the
    end entity certificate is stored in the trusted publisher store,
    implying that the user trusts content from this publisher.

    3) The end entity certificate has sufficient permission to sign
    code, as indicated by the presence of a code signing EKU or no
    EKU.
    */


    GUID WVTPolicyGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;   <---- error
    WINTRUST_DATA WinTrustData;                                                  <---- error

    // Initialize the WinVerifyTrust input data structure.

    // Default all fields to 0.
    memset(&WinTrustData, 0, sizeof(WinTrustData));

    WinTrustData.cbStruct = sizeof(WinTrustData);

    // Use default code signing EKU.
    WinTrustData.pPolicyCallbackData = NULL;

    // No data to pass to SIP.
    WinTrustData.pSIPClientData = NULL;

    // Disable WVT UI.
    WinTrustData.dwUIChoice = WTD_UI_NONE;

    // No revocation checking.
    WinTrustData.fdwRevocationChecks = WTD_REVOKE_NONE;

    // Verify an embedded signature on a file.
    WinTrustData.dwUnionChoice = WTD_CHOICE_FILE;

    // Default verification.
    WinTrustData.dwStateAction = 0;

    // Not applicable for default verification of embedded signature.
    WinTrustData.hWVTStateData = NULL;

    // Not used.
    WinTrustData.pwszURLReference = NULL;

    // This is not applicable if there is no UI because it changes
    // the UI to accommodate running applications instead of
    // installing applications.
    WinTrustData.dwUIContext = 0;

    // Set pFile.
    WinTrustData.pFile = &FileData;

    // WinVerifyTrust verifies signatures as specified by the GUID
    // and Wintrust_Data.
    lStatus = WinVerifyTrust(
        NULL,
        &WVTPolicyGUID,
        &WinTrustData);

    switch (lStatus)
    {
        case ERROR_SUCCESS:
            /*
            Signed file:
                - Hash that represents the subject is trusted.

                - Trusted publisher without any verification errors.

                - UI was disabled in dwUIChoice. No publisher or
                    time stamp chain errors.

                - UI was enabled in dwUIChoice and the user clicked
                    "Yes" when asked to install and run the signed
                    subject.
            */

            wprintf_s(L"The file \"%s\" is signed and the signature "
                L"was verified.\n",
                hb_parc(1)); //pwszSourceFile);
            break;

        case TRUST_E_NOSIGNATURE:
            // The file was not signed or had a signature
            // that was not valid.

            // Get the reason for no signature.
            dwLastError = GetLastError();
            if (TRUST_E_NOSIGNATURE == dwLastError ||
                    TRUST_E_SUBJECT_FORM_UNKNOWN == dwLastError ||
                    TRUST_E_PROVIDER_UNKNOWN == dwLastError)
            {
                // The file was not signed.
                wprintf_s(L"The file \"%s\" is not signed.\n",
                    hb_parc(1)); //pwszSourceFile);
            }
            else
            {
                // The signature was not valid or there was an error
                // opening the file.
                wprintf_s(L"An unknown error occurred trying to "
                    L"verify the signature of the \"%s\" file.\n",
                    hb_parc(1)); //pwszSourceFile);
                    //pwszSourceFile);
            }

            break;

        case TRUST_E_EXPLICIT_DISTRUST:
            // The hash that represents the subject or the publisher
            // is not allowed by the admin or user.
            wprintf_s(L"The signature is present, but specifically "
                L"disallowed.\n");
            break;

        case TRUST_E_SUBJECT_NOT_TRUSTED:
            // The user clicked "No" when asked to install and run.
            wprintf_s(L"The signature is present, but not "
                L"trusted.\n");
            break;

        case CRYPT_E_SECURITY_SETTINGS:
            /*
            The hash that represents the subject or the publisher
            was not explicitly trusted by the admin and the
            admin policy has disabled user trust. No signature,
            publisher or time stamp errors.
            */

            wprintf_s(L"CRYPT_E_SECURITY_SETTINGS - The hash "
                L"representing the subject or the publisher wasn't "
                L"explicitly trusted by the admin and admin policy "
                L"has disabled user trust. No signature, publisher "
                L"or timestamp errors.\n");
            break;

        default:
            // The UI was disabled in dwUIChoice or the admin policy
            // has disabled user trust. lStatus contains the
            // publisher or time stamp chain error.
            wprintf_s(L"Error is: 0x%x.\n",
                lStatus);
            break;
    }

    hb_retni(1);
 

#pragma ENDDUMP

 
FWH User
FWPPC User
FWLinux User
yunbg1
 
Posts: 107
Joined: Sun Nov 13, 2005 12:40 am
Location: Winnipeg Canada

Re: compile error. TO : Antonio.

Postby Antonio Linares » Mon Jul 29, 2013 10:17 am

Yung,

First of all you have to include the right header files:

#pragma BEGINDUMP

#include <windows.h>
#include <wintrust.h>
#include <hbapi.h>

but the first error you get is here:
FileData.pcwszFilePath = hb_parc(1);

because that member is of type LPCWSTR (wide string) and hb_parc( 1 ) returns a char * (standard string).

In a next msg I explain you how to do it...
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41921
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: compile error. TO : Antonio.

Postby Antonio Linares » Mon Jul 29, 2013 10:20 am

Code: Select all  Expand view
LPWSTR AnsiToWide( char * );

#pragma comment (lib, "wintrust")

HB_FUNC(TEST)
{
    LONG lStatus;
    DWORD dwLastError;

    // Initialize the WINTRUST_FILE_INFO structure.

    WINTRUST_FILE_INFO FileData;

    memset(&FileData, 0, sizeof(FileData));
    FileData.cbStruct = sizeof(WINTRUST_FILE_INFO);
    FileData.pcwszFilePath = AnsiToWide( ( char * ) hb_parc( 1 ) );
    FileData.hFile = NULL;
    FileData.pgKnownSubject = NULL;
 


please notice that AnsiToWide() allocates dynamic memory, that will have to be hb_xfree( ( void ) FileData.pcwszFilePath ); when it is no longer needed.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41921
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: compile error. TO : Antonio.

Postby Antonio Linares » Mon Jul 29, 2013 10:23 am

The next error is because the C language does not allow to declare a variable after some sentences (actions):

GUID WVTPolicyGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2; <---- error

The C++ language allows that, but not the C language. So take that line under the above variables declarations:

LONG lStatus;
DWORD dwLastError;
WINTRUST_FILE_INFO FileData;
GUID WVTPolicyGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2; <---- error

...

Have you used the C language before ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41921
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: compile error. TO : Antonio.

Postby yunbg1 » Mon Jul 29, 2013 1:30 pm

o My mistake..
sorry.

Thank you antonio.
FWH User
FWPPC User
FWLinux User
yunbg1
 
Posts: 107
Joined: Sun Nov 13, 2005 12:40 am
Location: Winnipeg Canada


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 25 guests