filemorph

Check-in [897c670d65]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Refine Windows exe; now changes working directory to location of script, launches much faster
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:897c670d655ed38a938e126cb3dc20a5ccdf6fc1
User & Date: kevin 2015-11-13 11:39:25
Context
2015-11-13
11:48
Additional tweaks check-in: 83230a13ac user: kevin tags: trunk
11:39
Refine Windows exe; now changes working directory to location of script, launches much faster check-in: 897c670d65 user: kevin tags: trunk
2015-11-12
12:20
Further refinement of Windows C exe check-in: 061f050393 user: kevin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to filemorph.c.

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80




#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <Windows.h>
#include <shlobj.h>



#ifndef CSIDL_APPDATA

#define CSIDL_APPDATA 0x001a 

#endif



static PerlInterpreter *my_perl;  /***    The Perl interpreter    ***/


EXTERN_C void xs_init (pTHX);

EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
EXTERN_C void boot_Win32CORE (pTHX_ CV* cv);

EXTERN_C void

xs_init(pTHX)
{


    static const char file[] = __FILE__;

    dXSUB_SYS;
    PERL_UNUSED_CONTEXT;

    /* DynaLoader is a special case */

    newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
    newXS("Win32CORE::bootstrap", boot_Win32CORE, file);

}

 int main( int argc , char **argv , char **env ) 


{    















    // shift argv and force parameters

    int num_forced_parameters = 4;

    argc += num_forced_parameters;

    int i;

    for(i=argc-1;i>num_forced_parameters;i--){
        argv[i]=argv[i-num_forced_parameters];
    }


    //argv[0] stores the relative path of the executable

    argv[1] = "-Ilib";
	argv[2] = "-Isite/lib";
	argv[3] = "-Ivendor/lib";
	
	
	//Construct absolute path to script so exe can be launched from anywhere.
	char appdata[MAX_PATH];
	BOOL ok = SHGetSpecialFolderPath(NULL, appdata, CSIDL_APPDATA, FALSE);
	char path[1024]; 
	strcpy(path, appdata);
	strcat(path,  "\\FileMorph_App\\filemorph\\filemorph.pl");

	argv[4] = path;
	printf("%s\n", path);
	printf("%d\n", strlen(path));

    PERL_SYS_INIT3( &argc , &argv , &env );
    my_perl = perl_alloc();
    perl_construct( my_perl );

    perl_parse( my_perl , xs_init , argc , argv , (char **)NULL );

    PL_exit_flags |= PERL_EXIT_DESTRUCT_END;

    perl_run( my_perl );
    perl_destruct( my_perl );
    perl_free( my_perl );
    PERL_SYS_TERM();
    return 0;

}










>
>


>

>

>
>



<

<


<

>

|
>
>

>




>


>



|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>












>






<
<
<
<
<
<
<
<
<
|
<
<




<

<

<








>
>
>
>
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76









77


78
79
80
81

82

83

84
85
86
87
88
89
90
91
92
93
94
95
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <Windows.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <tchar.h>

#ifndef CSIDL_APPDATA

#define CSIDL_APPDATA 0x001a 

#endif



static PerlInterpreter *my_perl;  /***    The Perl interpreter    ***/


EXTERN_C void xs_init (pTHX);

EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
EXTERN_C void boot_Win32CORE (pTHX_ CV* cv);

EXTERN_C void

xs_init(pTHX)

{

    static const char file[] = __FILE__;

    dXSUB_SYS;
    PERL_UNUSED_CONTEXT;

    /* DynaLoader is a special case */

    newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
    newXS("Win32CORE::bootstrap", boot_Win32CORE, file);

}

 int main( int argc , char **argv , char **env ) 
{    
	// Get current module's full path

   TCHAR exedir [MAX_PATH] = "";
   GetModuleFileName( 0, exedir, MAX_PATH );

   // Remove file part for e.g. SomeExe.exe from C:/SomeProgram/SomeExe.exe

   // include shlwapi.h and link to shlwapi.lib
   PathRemoveFileSpec(exedir);

  // char appdir = (char)exedir;
   //Change working directory to where exe is installed 

 //  chdir(appdir);

 SetCurrentDirectory(exedir);

    // shift argv and force parameters

    int num_forced_parameters = 4;

    argc += num_forced_parameters;

    int i;

    for(i=argc-1;i>num_forced_parameters;i--){
        argv[i]=argv[i-num_forced_parameters];
    }


    //argv[0] stores the relative path of the executable

    argv[1] = "-Ilib";
	argv[2] = "-Isite/lib";
	argv[3] = "-Ivendor/lib";









	argv[4]= "filemorph.pl";



    PERL_SYS_INIT3( &argc , &argv , &env );
    my_perl = perl_alloc();
    perl_construct( my_perl );

    perl_parse( my_perl , xs_init , argc , argv , (char **)NULL );

    PL_exit_flags |= PERL_EXIT_DESTRUCT_END;

    perl_run( my_perl );
    perl_destruct( my_perl );
    perl_free( my_perl );
    PERL_SYS_TERM();
    return 0;

}