Jump to content
Fórum Script Brasil
  • 0

Como compilar uma DLL corretamente?


Question

E ai Pessoal! Beleza?

Estou trabalhando com simulações no Ansys (AQWA) e estou tendo problemas para compilar uma DLL que exportará funções para a simulação. Estou usando o Visual Studio 2019, com  um tamplate Biblioteca de Vínculo Dinâmico (DLL). Sou bem iniciante com este tipo de programação, pelo desculpas caso o erro seja muito tolo

 

Esses são os meus algortimos:

 

 

//user_force64.cpp

#include "user_force.h"
#include "pch.h"
#include <stdio.h>

extern "C"
{

	__declspec(dllexport) void _stdcall USER_FORCE(int* Mode, int I_Control[100], float R_Control[100],
		int* Nstruc, float* Time, float* TimeStep, int* Stage,
		float Position[][6], float Velocity[][6], float Cog[][3],
		float Force[][6], float Addmass[][6][6], int* ErrorFlag)

	{

		//
		// *** Visual C++ Template
		// -----------------------
		//
		// 1. Uses stdcall calling convention
		// 2. Routine name MUST be in upper case
		// 3. All parameters are passed as pointers
		//
		// Input Parameter Description:
		//
		// Mode int*       - 0  = Initialisation. This routine is called once with mode 0
		//                        before the simulation. All parameters are as described
		//                        below except for STAGE, which is undefined. FORCES and
		//                        ADDMAS are assumed undefined on exit.
		//                        IERR if set to > 0 on exit will cause
		//                        the simulation to stop.
		//
		//                   1  = Called during the simulation. FORCE/ADDMAS output expected.
		//
		//                   99 = Termination. This routine is called once with mode 99
		//                        at the end of the simulation.
		//
		// I_Control[100]  - User-defined integer control parameters input in .DAT file.
		// (int*)
		//
		// R_Control[100]  - User-defined real control parameters input in .DAT file.
		// (float*)
		//
		// Nstruc int*     - Number of structures in the the simulation
		//
		// Time float*     - The current time (see Stage below)
		//
		// Timestep float* - The current timestep (DT, see Stage below)
		//
		// Stage int*      - The stage of the integration scheme. AQWA time integration is
		//                   based on a 2-stage predictor corrector method. This routine is
		//                   therefore called twice at each timestep, once with STAGE=1 and
		//                   once with STAGE=2. On stage 2 the position and velocity are
		//                   predictions of the position and velocity at TIME+DT.
		//                   e.g. if the initial time is 0.0 and the step 1.0 seconds then
		//                   calls are as follows for the 1st 3 integration steps:
		//
		//                   CALL USER_FORCE(.....,TIME=0.0,TIMESTEP=1.0,STAGE=1 ...)
		//                   CALL USER_FORCE(.....,TIME=0.0,TIMESTEP=1.0,STAGE=2 ...)
		//                   CALL USER_FORCE(.....,TIME=1.0,TIMESTEP=1.0,STAGE=1 ...)
		//                   CALL USER_FORCE(.....,TIME=1.0,TIMESTEP=1.0,STAGE=2 ...)
		//                   CALL USER_FORCE(.....,TIME=2.0,TIMESTEP=1.0,STAGE=1 ...)
		//                   CALL USER_FORCE(.....,TIME=2.0,TIMESTEP=1.0,STAGE=2 ...)
		//
		// Cog[Nstruc][3]  - Position of the Centre of Gravity in the Definition axes.
		//
		// Position[Nstruc][6] - Position of the structure in the FRA - angles in radians
		// (float*)
		//
		// Velocity[Nstruc][6] - Velocity of the structure in the FRA
		// (float*)              angular velocity in rad/s
		//
		//
		// Output Parameter Description:
		//
		// Force[Nstruc][6] - Force on the Centre of gravity of the structure. NB: these
		// (float)           forces are applied in the Fixed Reference axis e.g.
		//                   the surge(X) force is ALWAYS IN THE SAME DIRECTION i.e. in
		//                   the direction of the X fixed reference axis.
		//
		// Addmass[Nstruc][6][6]
		// (float)         - Added mass matrix for each structure. As the value of the
		//                   acceleration is dependent on FORCES, this matrix may be used
		//                   to apply inertia type forces to the structure. This mass
		//                   will be added to the total added mass of the structure at each
		//                   timestep at each stage.
		//
		// Errorflag int*  - Error flag. The program will abort at any time if this
		//                   error flag is non-zero. The values of the error flag will
		//                   be output in the abort message.


	

		int i, j;
		int struc = 1;

		//------------------------------------------------------------------------
		// MODE#0 - Initialise any summing variables/open/create files.
		//          This mode is executed once before the simulation begins.
		//------------------------------------------------------------------------

		if (*Mode == 0)
		{
		}

		//------------------------------------------------------------------------
		// MODE#1 - On-going - calculation of forces/mass
		//------------------------------------------------------------------------

		else if (*Mode == 1)
		{
			for (struc = 0; struc < *Nstruc; struc++)
			{
				for (i = 0; i < 6; i++)
				{
					Force[struc][i] = 2 * Velocity[struc][i];
					for (j = 0; j < 6; j++)
					{
						Addmass[struc][j][i] = 0.0;
					}
				}
			}
			*ErrorFlag = 0;
		}

		//------------------------------------------------------------------------
		// MODE#99 - Termination - Output/print any summaries required/Close Files
		//           This mode is executed once at the end of the simulation
		//------------------------------------------------------------------------

		else if (*Mode == 99)
		{
		}

		//------------------------------------------------------------------------
		// MODE# ERROR - OUTPUT ERROR MESSAGE
		//------------------------------------------------------------------------

		else
		{
		}

		return;
	}
}

--------------------------------------------------------------------

 

//user_force.h
#pragma once

extern "C"
{

	__declspec(dllexport) void _stdcall USER_FORCE(int* Mode, int I_Control[100], float R_Control[100],
		int* Nstruc, float* Time, float* TimeStep, int* Stage,
		float Position[][6], float Velocity[][6], float Cog[][3],
		float Force[][6], float Addmass[][6][6], int* ErrorFlag)
}

--------------------------------------------------------------------------

// dllmain.cpp : Define o ponto de entrada para o aplicativo DLL.
#include "pch.h"

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

Depois de usar o comando dumpbin /exports na DLL gerada, esta é a mensagem:

 Section contains the following exports for user_force64.dll

    00000000 characteristics
    FFFFFFFF time date stamp
        0.00 version
           1 ordinal base
           1 number of functions
           1 number of names

    ordinal hint RVA      name

          1    0 00011046 [email protected] = @ILT+65([email protected])

  Summary

        1000 .00cfg
        1000 .data
        1000 .idata
        1000 .msvcjmc
        2000 .rdata
        1000 .reloc
        1000 .rsrc
        6000 .text
       10000 .textbss

E quando uso o mesmo comando em uma DLL funcional, este é o output

Dump of file user_force64.dll

File Type: DLL

  Section contains the following exports for user_force64.dll

    00000000 characteristics
    5D3F15AA time date stamp Mon Jul 29 12:50:02 2019
        0.00 version
           1 ordinal base
           1 number of functions
           1 number of names

    ordinal hint RVA      name

          1    0 00001000 USER_FORCE

  Summary

        1000 .data
        1000 .pdata
        1000 .rdata
        1000 .reloc
        1000 .rsrc
        1000 .text

 

Aparentemente errei alguma coisa na compilação, o que causou a diferença no nome da função exportada

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Cloud Computing


  • Forum Statistics

    • Total Topics
      148691
    • Total Posts
      644530
×
×
  • Create New...