-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVBAScriptGenerator.cpp
More file actions
61 lines (31 loc) · 1.29 KB
/
VBAScriptGenerator.cpp
File metadata and controls
61 lines (31 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <windows.h>
#include <fstream>
#include "VBAScriptGenerator.h"
void generateVBAScript(const std::string& scriptfileName)
{
const std::string DLL_64 = getCurrentDirectory() + "\\urdu64.dll";
const std::string DLL_32 = getCurrentDirectory() + "\\urdu32.dll";
std::ofstream ofs(scriptfileName + ".bas");
ofs << "Attribute VB_Name = \"loader\" " << std::endl;
ofs << "#If VBA7 Then " << std::endl;
ofs << " Private Declare PtrSafe Function toUrdu Lib "<< "\"" << DLL_64 << "\"" <<" (ByVal a As String) As String" << std::endl;
ofs << "#Else" << std::endl;
ofs << " Private Declare Function toUrdu Lib " << "\"" << DLL_32 << "\"" << " (ByVal a As String) As String" << std::endl;
ofs << "#End If" << std::endl << std::endl;
ofs << "Function URDU(digits As String)" << std::endl;
ofs << " URDU = StrConv(toUrdu(digits), vbFromUnicode)" << std::endl;
ofs << "End Function" << std::endl;
ofs.close();
}
std::string getCurrentDirectory()
{
TCHAR Buffer[MAX_PATH];
DWORD dwRet;
dwRet = GetCurrentDirectory(MAX_PATH, Buffer);
if( dwRet == 0 )
std::cout << "GetCurrentDirectory failed " << GetLastError();
if(dwRet > MAX_PATH)
std::cout << "Buffer too small; need %d characters\n" << dwRet;
return std::string(Buffer);
}