LibreOffice Module basic (master) 1
dllmgr-none.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <sal/config.h>
21
22#if defined(_WIN32)
23#include <prewin.h>
24#include <postwin.h>
25#endif
26
27#include <basic/sberrors.hxx>
28#include <basic/sbx.hxx>
29#include <basic/sbxvar.hxx>
30#include <rtl/ustring.hxx>
31#include <osl/time.h>
32
33#include "dllmgr.hxx"
34
35namespace {
36
37// Overcome the mess of Currency vs. custom types etc.
38ErrCode returnInt64InOutArg(SbxArray *pArgs, SbxVariable &rRetVal,
39 sal_Int64 nValue)
40{
41 if (!rRetVal.PutLong(1) && !rRetVal.PutInteger(1))
43 if (!pArgs || pArgs->Count() != 2)
45 SbxVariable* pOut = pArgs->Get(1);
46 if (!pOut)
48 if (pOut->IsCurrency())
49 {
50 pOut->PutCurrency(nValue);
51 return ERRCODE_NONE;
52 }
53 if (!pOut->IsObject())
55
56 // FIXME: should we clone this and use pOut->PutObject ?
57 SbxObject* pObj = dynamic_cast<SbxObject*>( pOut->GetObject() );
58 if (!pObj)
60
61 // We expect two Longs but other mappings could be possible too.
62 SbxArray* pProps = pObj->GetProperties();
63 if (pProps->Count() != 2)
65 SbxVariable* pLow = pProps->Get(0);
66 SbxVariable* pHigh = pProps->Get(1);
67 if (!pLow || !pLow->IsLong() ||
68 !pHigh || !pHigh->IsLong())
70 pLow->PutLong(nValue & 0xffffffff);
71 pHigh->PutLong(nValue >> 32);
72 return ERRCODE_NONE;
73}
74
75ErrCode builtin_kernel32(std::u16string_view aFuncName, SbxArray *pArgs,
76 SbxVariable &rRetVal)
77{
78 sal_Int64 nNanoSecsPerSec = 1000.0*1000*1000;
79 if (aFuncName == u"QueryPerformanceFrequency")
80 return returnInt64InOutArg(pArgs, rRetVal, nNanoSecsPerSec);
81
82 else if (aFuncName == u"QueryPerformanceCounter")
83 {
84 TimeValue aNow;
85 osl_getSystemTime( &aNow );
86 sal_Int64 nStamp = aNow.Nanosec + aNow.Seconds * nNanoSecsPerSec;
87 return returnInt64InOutArg(pArgs, rRetVal, nStamp);
88 }
90}
91
92};
93
95 std::u16string_view aFuncName, std::u16string_view aDllName,
96 SbxArray *pArgs, SbxVariable &rRetVal,
97 SAL_UNUSED_PARAMETER bool /* bCDecl */)
98{
99 if (aDllName == u"kernel32")
100 return builtin_kernel32(aFuncName, pArgs, rRetVal);
101 else
103}
104
105void SbiDllMgr::FreeDll(SAL_UNUSED_PARAMETER OUString const &) {}
106
107SbiDllMgr::SbiDllMgr() = default;
108
109#if defined(_WIN32) && !defined(_ARM64_)
110SbiDllMgr::~SbiDllMgr() = default;
111#endif
112
113/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ErrCode Call(std::u16string_view function, std::u16string_view library, SbxArray *arguments, SbxVariable &result, bool cdeclConvention)
Definition: dllmgr-none.cxx:94
void FreeDll(OUString const &library)
Definition: sbx.hxx:95
sal_uInt32 Count() const
Definition: sbxarray.cxx:87
SbxVariable * Get(sal_uInt32)
Definition: sbxarray.cxx:108
SbxArray * GetProperties()
Definition: sbxobj.hxx:79
bool PutInteger(sal_Int16)
bool IsLong() const
Definition: sbxvar.hxx:117
bool PutLong(sal_Int32)
float u
#define ERRCODE_NONE
#define ERRCODE_BASIC_BAD_ARGUMENT
Definition: sberrors.hxx:26
#define ERRCODE_BASIC_NOT_IMPLEMENTED
Definition: sberrors.hxx:80
oslFileHandle & pOut