The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Returning a complex number using a DLL file

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
shafei Posted - 03/31/2012 : 9:19:29 PM
Origin Ver. and Service Release (Select Help-->About Origin): 8.1 & 8.6
Operating System:8
Hi, I am trying to generate a DLL code so that my Origin C code runs faster. The code generates a complex number which is being used in another code. Let's assume my origin code is something like this:

complex Xnm(double x1, double y1)
{
complex eye(0.0, 1.0);
complex xnm = x1 + eye*y1;
return xnm;
}
This code is handled easily in OriginC. However the problem arises when I use visual studio (VC) to generate a DLL file out of the code above. The problem is that, if I am not wrong, C++ does not have complex class like Origin, such that VC can not return a complex number. I can only explore the real or imaginary parts of the complex number. If I want to do this, it doubles the time the code needs to be executed.
Do you have any suggestions on how to convert my Origin C code to a dll file using VC such that the returned value is a complex?
Thank you!
5   L A T E S T    R E P L I E S    (Newest First)
eparent Posted - 04/17/2012 : 5:17:35 PM
1. Origin C passes a vector<type> to a DLL function as a pointer to the type. The DLL function would not know the size of the vector unless you also passed in the size as another argument. Have you tried expanding the code I gave you earlier to accept a pointer to that struct?

2. The code I gave you earlier showed you how to pass a complex from Origin C to a DLL and you agreed it was working. It is not clear what you are asking now.

quote:
Originally posted by shafei

I asked this question because of the following reasons:
1. In Origin C 2-D vectors are matrices and C++ they are defined as vectors. Does Origin C recognize vector in a dll file made by C++?
2. The second problem is that in the argument of the function, I have complex numbers. Origi C handles them very well, however, I am not sure how I can use complex variables in an argument of a function in C++.
Thanks


shafei Posted - 04/06/2012 : 3:03:32 PM
I asked this question because of the following reasons:
1. In Origin C 2-D vectors are matrices and C++ they are defined as vectors. Does Origin C recognize vector in a dll file made by C++?
2. The second problem is that in the argument of the function, I have complex numbers. Origi C handles them very well, however, I am not sure how I can use complex variables in an argument of a function in C++.
Thanks
shafei Posted - 04/05/2012 : 02:56:09 AM
Following up with the past discussion, I have the following code in Origin C:
double BetaIntXYZ(int& N, matrix<complex>& xMoments, matrix<complex>& yMoments,
matrix<complex>& zMoments, vector& Energy, double& R)
{
int i,j;
complex value(0.0, 0.0);

for(i = 0; i< 2*N+1; i++)
{
for(j = 0; j< 2*N+1; j++)
{
if (i != N && j != N)
{
value = value + (0.75)^(0.75) * ((2*pi/R)^3) *
( xMoments[N][i] * yMoments[i][j] * zMoments[j][N] +
xMoments[N][i] * zMoments[i][j] * yMoments[j][N] +
zMoments[N][i] * xMoments[i][j] * yMoments[j][N] )
/Energy[i]/Energy[j]/3;
}
}
}

double realValue = value.m_re;
//printf("%f\n", realValue);

return realValue;
}

I want to take this code to VC, make a dll of it, and then use the dll in Origin code. Can you please let me know how the code should change, as the definition of complex and vectors are different in Origin C and VC?
Thank you!
shafei Posted - 04/04/2012 : 03:46:46 AM
I used it in VC and then made a Dll file. It works flawlessly. Thank you eparent!
eparent Posted - 04/03/2012 : 10:31:25 AM
C++ has a complex class but it is not the same as Origin C's complex. In VC you will have to do this:

#include <complex>

typedef struct {
	double real;
	double imag;
} complex_t;


extern "C" complex_t Xnm(double x1, double y1)
{
	std::complex<double> eye(0.0, 1.0);
	std::complex<double> xnm = x1 + eye*y1;

	complex_t ret;
	ret.real = xnm.real();
	ret.imag = xnm.imag();
	return ret;
}

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000