Przeglądaj źródła

dll export now produces prudent dll file, dll import causes VS to terminate program without error message

Vincenz Mechler 5 lat temu
rodzic
commit
664d278828

+ 1 - 1
SketchAssistant/SketchAssistant.sln

@@ -53,7 +53,7 @@ Global
 		{EB09C624-91F2-465F-825B-559BF7A7D5CB}.Release|x64.Build.0 = Release|Any CPU
 		{EB09C624-91F2-465F-825B-559BF7A7D5CB}.Release|x86.ActiveCfg = Release|Any CPU
 		{EB09C624-91F2-465F-825B-559BF7A7D5CB}.Release|x86.Build.0 = Release|Any CPU
-		{9ED853D5-40BD-40EB-9F8F-228EE11319A1}.Debug|Any CPU.ActiveCfg = Debug|x64
+		{9ED853D5-40BD-40EB-9F8F-228EE11319A1}.Debug|Any CPU.ActiveCfg = Debug|Win32
 		{9ED853D5-40BD-40EB-9F8F-228EE11319A1}.Debug|x64.ActiveCfg = Debug|x64
 		{9ED853D5-40BD-40EB-9F8F-228EE11319A1}.Debug|x64.Build.0 = Debug|x64
 		{9ED853D5-40BD-40EB-9F8F-228EE11319A1}.Debug|x86.ActiveCfg = Debug|Win32

+ 6 - 3
SketchAssistant/SketchAssistantWPF/LocalArmbandInterface.cs

@@ -10,13 +10,16 @@ namespace SketchAssistantWPF
     class LocalArmbandInterface
     {
 
-        [DllImport (@"StaticLibMotors.dll")]
+        [DllImport (@"../Debug/StaticLibMotors.dll", EntryPoint = "?setupArmband@ArmbandInterface@@QAAHXZ",
+     CallingConvention = CallingConvention.Cdecl)]
         public static extern int setupArmband();
 
-        [DllImport(@"StaticLibMotors.dll")]
+        [DllImport(@"../Debug/StaticLibMotors.dll", EntryPoint = "?startVibrate@ArmbandInterface@@QAAXHM@Z",
+     CallingConvention = CallingConvention.Cdecl)]
         public static extern void startVibrate(int motorNumber, float intensity);
 
-        [DllImport(@"StaticLibMotors.dll")]
+        [DllImport(@"../Debug/StaticLibMotors.dll", EntryPoint = "?stopVibrate@ArmbandInterface@@QAAXH@Z",
+     CallingConvention = CallingConvention.Cdecl)]
         public static extern void stopVibration(int motorNumber);
 
         //public void Vibrate()

BIN
SketchAssistant/SketchAssistantWPF/StaticLibMotors.dll


+ 22 - 5
SketchAssistant/StaticLib1/ArmbandInterface.cpp

@@ -5,10 +5,23 @@ extern "C" {
 #include <ctime>
 #include <stdio.h>
 #include "ArmbandInterface.h"
+#include <stdlib.h>
 
+typedef void(__cdecl *InitFunctionType)(BodyActuator*, BodyActuator_Type, char*, int);
+typedef void(__cdecl *StopFunctionType)(BodyActuator*, uint8_t);
+typedef void(__cdecl *StartFunctionType)(BodyActuator*, uint8_t, float);
+
+static InitFunctionType initFunctionHandle;
+static StartFunctionType startFunctionHandle;
+static StopFunctionType stopFunctionHandle;
+
+static BodyActuator* armband;
+//static char *port = 
+
+static HINSTANCE lib;
 
 extern "C" {
-		__declspec(dllexport) int __cdecl ArmbandInterface::setupArmband() {
+	DllExport int __cdecl ArmbandInterface::setupArmband() {
 			lib = LoadLibrary(TEXT("BodyActuator.dll"));
 			if (lib == NULL) {
 				printf("ERROR: library could not be loaded");
@@ -34,16 +47,20 @@ extern "C" {
 			startVibrate(0, 1.0);
 			return -1;
 		}
-		__declspec(dllexport) void __cdecl ArmbandInterface::startVibrate(int tactor, float intensity) {
+
+		DllExport void __cdecl ArmbandInterface::startVibrate(int tactor, float intensity) {
 			(startFunctionHandle)(armband, (uint8_t)tactor, intensity);
 		}
-		__declspec(dllexport) void __cdecl ArmbandInterface::stopVibrate(int tactor) {
+
+		DllExport void __cdecl ArmbandInterface::stopVibrate(int tactor) {
 			(stopFunctionHandle)(armband, (uint8_t)tactor);
 		}
 	}
 
  void ArmbandInterface::setupMotors() {
-			(initFunctionHandle) (armband, BODYACTUATOR_TYPE_EAI, new char[5]{ 'C', 'O', 'M', '5', '\0' }, 8);
+	 char* port = (char*) "COM5";//malloc(7);
+	 armband = (BodyActuator*) malloc(sizeof(BodyActuator*));
+	 //strcpy_s(port, "COM5");
+			(initFunctionHandle) (armband, BODYACTUATOR_TYPE_EAI, port, 8);
 			printf("armband initialized");
 		}
- 

+ 2 - 6
SketchAssistant/StaticLib1/ArmbandInterface.h

@@ -15,17 +15,13 @@ DllExport void stopVibrate(int tactor);
 
 class ArmbandInterface
 {
-
-	static BodyActuator* armband;
-	//static char *port = 
-
-	static HINSTANCE lib;
+	/*
 	typedef void(__cdecl *InitFunctionType)(BodyActuator*, BodyActuator_Type, char*, int);
 	static InitFunctionType initFunctionHandle;
 	typedef void(__cdecl *StartFunctionType)(BodyActuator*, uint8_t, float);
 	static StartFunctionType startFunctionHandle;
 	typedef void(__cdecl *StopFunctionType)(BodyActuator*, uint8_t);
-	static StopFunctionType stopFunctionHandle;
+	static StopFunctionType stopFunctionHandle; */
 
 	public:
 		__declspec(dllexport) int __cdecl  setupArmband();

+ 3 - 1
SketchAssistant/StaticLib1/StaticLib1.vcxproj

@@ -96,7 +96,7 @@
     <Link>
       <SubSystem>Windows</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -107,10 +107,12 @@
       <SDLCheck>true</SDLCheck>
       <PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <ConformanceMode>true</ConformanceMode>
+      <AdditionalIncludeDirectories>C:\Users\01100\csharp\BP-SketchAssistant\SketchAssistant\StaticLib1;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">