Question

I generated C++ shared library in MATLAB and integrated it in Win32 console application in C++. I have to call this console application from PHP.It has 5 inputs which should be passed from php. When I run the application giving the input parameters it runs. The code which runs properly is as below:

#include "stdafx.h"
#include "shoes_sharedlibrary.h"
#include <iostream>
#include <string.h>
#include "mex.h"



using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    /* Call the MCR and library initialization functions */
if( !mclInitializeApplication(NULL,0) )
{

    exit(1);
}

if (!shoes_sharedlibraryInitialize())
{

    exit(1);
}



     mwArray img= "C:/Users/aadbi.a/Desktop/dressimages/T1k5aHXjNqXXc4MOI3_050416.jpg";
     double wt1 = 0;
     mwArray C(wt1);
     double wt2=0;
     mwArray F(wt2);
     double wt3=0;
     mwArray T(wt3);
     double wt4=1;
     mwArray S(wt4);



           test_shoes(img,C,F,T,S);
            shoes_sharedlibraryTerminate();
            mclTerminateApplication();
            return 0;
}

The C,F,T,S are value between 0 and 1. How can I pass the input arguments as it is in _TCHAR*?How can I convert the _TCHAR* into decimal or double and again converting that into mwArray to pass into test_shoes. The test_shoes only takes mwArray as input.

The test_shoes function definition is:

void MW_CALL_CONV test_shoes(const mwArray& img_path, const mwArray& Wcoarse_colors, 
                             const mwArray& Wfine_colors, const mwArray& Wtexture, const 
                             mwArray& Wshape)
{
  mclcppMlfFeval(_mcr_inst, "test_shoes", 0, 0, 5, &img_path, &Wcoarse_colors, &Wfine_colors, &Wtexture, &Wshape);
}
Was it helpful?

Solution

You can convert the command line string arguments to double using the atof() function from stdlib.h. As I see you are using the TCHAR equivalents, there is a macro that wraps the correct call for UNICODE and ANSI builds, so you can do something like this (assuming your command line arguments are in the correct order)

#include "stdafx.h"
#include "shoes_sharedlibrary.h"
#include <iostream>
#include <string.h>
#include "mex.h"

#include <stdlib.h>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    // ... initial code

    // convert command line arguments to doubles ...
    double wt1 = _tstof(argv[1]);
    mwArray C(wt1);
    double wt2 = _tstof(argv[2]);
    mwArray F(wt2);
    double wt3 = _tstof(argv[3]);
    mwArray T(wt3);

    // ... and so on ....
}

Note that argv[0] will contain the name of your program as specified on the command line, so the arguments begin at argv[1]. Then your command line can be something like:

yourprog.exe 0.123 0.246 0.567 etc.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top