| |

VerySource

 Forgot password?
 Register
Search
View: 1247|Reply: 11

C ++ Error compiling dynamic link library, help! Thank you

[Copy link]

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-30 11:40:02
| Show all posts |Read mode
head File
// myTime.h
__declspec (dllexport) void Func1 ();
__declspec (dllexport) void Func2 ();
__declspec (dllexport) bool timeCompare (string time1, string time2);


cpp;
// myTime.cpp
#include "myTime.h"
#include <string>
// # include <iostream>
void Func1 () {
// std :: cout << "Tsinghua\n";
}
void Func2 () {
// std :: cout << "C ++ OOP\n";
}
bool timeCompare (string time1, string time2) {
// Compare the time of two string classes
int time1Lenth = time1.size ();
int time2Lenth = time2.size ();

if (time1Lenth> time2Lenth) {
for (int i = 0; i <time1Lenth-time2Lenth; i ++)
if (time1 [i]! = '0')
return true;
}

if (time1Lenth <time2Lenth) {
for (int i = 0; i <time1Lenth-time2Lenth; i ++)
if (time2 [i]! = '0')
return false;
}

if (time1Lenth == time2Lenth) {
for (int i = 0; i <time1Lenth; i ++) {
if (time1 [i]> time2 [i])
return true;
if (time1 [i] <time2 [i])
return false;

}
if (time1 [time1Lenth-1] == time2 [time2Lenth-1])
return true;
return false;

}
return false;
}
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-6 17:15:01
| Show all posts
__declspec (dllexport) also needs to be added when function definition
Reply

Use magic Report

0

Threads

55

Posts

44.00

Credits

Newbie

Rank: 1

Credits
44.00

 Invalid IP Address

Post time: 2020-3-6 20:30:02
| Show all posts
What's wrong?
You use string as a parameter, you must use extended dll mode. And this dll cannot be used across compilers.
Use char * instead
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-3-11 13:45:01
| Show all posts
Changing to char * has changed a lot and the function has to be changed
I am a beginner, please give some specific answers
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-3-11 14:30:01
| Show all posts
Can you compile it for me
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-3-11 23:45:01
| Show all posts
superandy
How to convert string and char *
Reply

Use magic Report

0

Threads

55

Posts

44.00

Credits

Newbie

Rank: 1

Credits
44.00

 Invalid IP Address

Post time: 2020-3-12 22:30:02
| Show all posts
bool timeCompare (char * time1_c, char * time2_c) {
string time1 (time1_c), time2 (time2_c);
Just
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-3-16 14:45:01
| Show all posts
What about string?
Reply

Use magic Report

0

Threads

55

Posts

44.00

Credits

Newbie

Rank: 1

Credits
44.00

 Invalid IP Address

Post time: 2020-3-16 18:00:01
| Show all posts
time1.c_str ()
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-3-17 12:30:01
| Show all posts
superandyreported wrong
Mybank.cpp (128): error C2664: 'timeCompare': cannot convert parameter 1 from '
const char * 'to' char * '
        Conversion loses qualifiers


I want to change the original string to char * class
The call is to change the time1 and time2 of the string to the char * class

if (timeCompare (cos.begin.c_str (), readyTime.c_str ()))

Thank you
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list