C/C ++ calls the MLu Entry Program

Source: Internet
Author: User

 

MLu is an interface library between the program and the Lu core library. MLu automatically loads the Lu core library and dynamically loads multiple Lu extension libraries, which simplifies the use of the Lu system; MLu can modularize the Lu source program and compile and run a source program (string expression) in a fixed format. C ++-style annotations can be used in the source program. In addition, MLu also provides multiple threads to access Lu resources mutex, and provides the Lu running monitor to exit a long program; provides the function of dynamically compiling functions in scripts, error handling functions, and recovery models for error (exception) processing.

 

1 implicit loading example

 

This example requires the following files:

 

(1) the header file lu32.h.

(2) import data to lu32.lib and mlu32.lib.

(3) The core library lu32.dll and the modular compilation Runtime Library mlu32.dll.

 

 

# Include <windows. h>

# Include <iostream>

# Include "lu32.h" // Lu header file

# Pragma comment (lib, "lu32.lib ")

# Pragma comment (lib, "mlu32.lib ")

Using namespace std;

Void main (void)

{

Void * hModule; // module handle

LuINT ErrBegin, ErrEnd; // The initial location and end location of the expression compilation Error

Int I; // error code

Void * hFor; // expression handle

LuVOID nModule = 0; // module where the expression is located

Void * vPara; // array pointer for storing input independent variables

LuData * pPara; // array pointer for storing input independent variables

LuINT nPara; // number of independent variables in the expression

LuData Val; // store the expression value

Wchar_t ForStr [] = L "f (x) = x + 1;: ff (x, y) = f (x) + y;"; // Lu modular source program

If (! InitMLu () return; // initialize the MLu

If (! UseLu (2) // apply to use Lu Resources

{

I = ComModule (ForStr, nModule, hModule, ErrBegin, ErrEnd); // compile the Lu source program

If (I)

{

Cout <"Lu source code error! Error Code: "<I <endl;

}

Else

{

If (GetFor (L "ff", 1, NULL, nModule, hFor, vPara, nPara) // query global functions

{

PPara = (LuData *) vPara;

For (I = 0; I <= nPara; I ++) // assign a value to the independent variable of the expression. All values are 1.

{

PPara [I]. BType = luStaData_int64; pPara [I]. VType = luStaData_int64; pPara [I]. x = 1;

}

Val = LuCal (hFor, pPara); // calculates the expression value

Cout <Val. x <endl;

}

Else

{

Cout <"the specified function cannot be found! "<Endl;

}

}

UseLu (0); // return the right to use Lu

}

FreeMLu (); // release the MLu

}

 

Result:

 

3

Press any key to continue...

 

2 explicit loading example

 

This example requires the following files:

 

(1) the header file lu32.h.

(2) The core library lu32.dll and the modular compilation Runtime Library mlu32.dll.

 

 

# Include <windows. h>

# Include <iostream>

# Include "Lu32.h"

Using namespace std;

HINSTANCE hMLu = NULL; // handle of the dynamic library MLu32.dll

 

// MLu output function

MluInitMLu pInitMLu;

MluFreeMLu pFreeMLu;

MluGetLuProc pGetLuProc;

MluUseLu pUseLu;

MluComModule pComModule;

// Lu output function

LuGetFor pGetFor;

LuLuCal pLuCal;

Bool theInitMLu (void) // initialize the MLu

{

HMLu = LoadLibrary (L "MLu32.dll"); // load the dynamic library MLu32.dll

If (! HMLu)

{

Cout <"MLu32.dll not found! Put this library in the WINDOWS Search Path! ";

Return false;

}

// Obtain the output function of MLu32.dll using the following statements:

PInitMLu = (mluInitMLu) GetProcAddress (hMLu, "InitMLu ");

PFreeMLu = (mluFreeMLu) GetProcAddress (hMLu, "FreeMLu ");

PGetLuProc = (mluGetLuProc) GetProcAddress (hMLu, "GetLuProc ");

PUseLu = (mluUseLu) GetProcAddress (hMLu, "UseLu ");

PComModule = (mluComModule) GetProcAddress (hMLu, "ComModule ");

If (! PInitMLu () // initialize MLu32.dll

{

FreeLibrary (hMLu); // release the dynamic library

Cout <"MLu initialization failed! ";

Return false;

}

// Obtain the output functions of Lu32.dll using the following statements:

PGetFor = (luGetFor) pGetLuProc ("GetFor ");

PLuCal = (luLuCal) pGetLuProc ("LuCal ");

Return true;

}

Void theFreeMLu (void) // release the MLu

{

PFreeMLu (); // release the space requested by the MLu.

FreeLibrary (hMLu); // release the dynamic library

}

Void main (void)

{

Void * hModule; // module handle

LuINT ErrBegin, ErrEnd; // The initial location and end location of the expression compilation Error

Int I; // error code

Void * hFor; // expression handle

LuVOID nModule = 0; // module where the expression is located

Void * vPara; // array pointer for storing input independent variables

LuData * pPara; // array pointer for storing input independent variables

LuINT nPara; // number of independent variables in the expression

LuData Val; // store the expression value

Wchar_t ForStr [] = L "f (x) = x + 1;: ff (x, y) = f (x) + y;"; // Lu modular source program

If (! TheInitMLu () return; // initialize the MLu

If (! PUseLu (2) // apply to use Lu Resources

{

I = pComModule (ForStr, nModule, hModule, ErrBegin, ErrEnd); // compile the Lu source program

If (I)

{

Cout <"Lu source code error! Error Code: "<I <endl;

}

Else

{

If (pGetFor (L "ff", 1, NULL, nModule, hFor, vPara, nPara ))

{

PPara = (LuData *) vPara;

For (I = 0; I <= nPara; I ++) // assign a value to the independent variable of the expression. All values are 1.

{

PPara [I]. BType = luStaData_int64; pPara [I]. VType = luStaData_int64; pPara [I]. x = 1;

}

Val = pLuCal (hFor, pPara); // calculates the expression value

Cout <Val. x <endl;

}

Else

{

Cout <"the specified function cannot be found! "<Endl;

}

}

PUseLu (0); // return the right to use Lu

}

TheFreeMLu (); // release the MLu

}

 

Result:

 

3

Press any key to continue.

 

From the forcal Column

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.