How can I solve this?
-
04 Nisan 2012 Çarşamba 01:44
C++ h.file
//unsigned int NorthWall[256];
//unsigned int EastWall[256];
unsigned int NorthWall[256];
unsigned int EastWall[256];
unsigned int NorthWall_Flash[256];
unsigned int EastWall_Flash[256];C++ cpp.file
void SearchToGoal(unsigned int* northWall, unsigned int* eastWall)
{
DashFlag=0;
Solver(CurrentXY, DashFlag);
BestPathFinder(Goal_XY1, Goal_XY2, Goal_XY3, Goal_XY4, DashFlag);
MCommandGen(Goal_XY1, Goal_XY2, Goal_XY3, Goal_XY4);
NorthWall = northWall; //y
EastWall = eastWall; //x}
***The errors are the bold worlds.. ERROR: expression must be a modifiable lvalue***
Tüm Yanıtlar
-
04 Nisan 2012 Çarşamba 01:59What are you trying to do? Are you trying to copy the contents of the array pointed to by northWall to the array defined by NorthWall? Or are you trying to assign a pointer to an array to another pointer?
-
04 Nisan 2012 Çarşamba 02:19I'm trying to pass an array from my C# program to this C++ program.. what else I have to show you in order for you to know how to help me?
-
04 Nisan 2012 Çarşamba 02:40
If you want to copy the contents of the array, then use memcpy(), as in:
memcpy (NorthWall, northWall, sizeof (NorthWall));
You need to ensure that the array size of NorthWall is sufficient.
By the way, where is your C# code? Are you using PInvoke to call the C++ function?
- Yanıt Olarak Öneren Helen ZhaoModerator 05 Nisan 2012 Perşembe 08:41
-
04 Nisan 2012 Çarşamba 09:08
my c# ARRAY.... still have some errors (those bold ones)
got wall means 1, no wall means 0
//Wall array
//Vertical (16x16)
int[][] a = new int[][] {new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
//Horizontal (16x16)
int[][] b = new int[][]{ new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
int x = 0;
int y = 0;//Mouse array
//Vertical (16x16)
int[][] northWall = new int[][]{new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
//Horizontal (16x16)
int[][] eastWall = new int[][]{ new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};int x1 = 0;
int y1 = 0;.............
................
.......................
private void btnRun_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}private void timer1_Tick(object sender, EventArgs e)
{
label7.Text = Convert.ToString(Add(5.0, 6.0));northWall[15][0] = a[15][0]; // x=0,y=0
eastWall[14][0] = b[14][0];
// pass to solver
// solver(...)
SearchToGoal(northWall, eastWall);
// solver return mouse command
//mouse move .. update x ,y
northWall[15 - y][0] = a[15 - y][0]; // x=0,y=1
eastWall[14 - y][0] = b[14 - y][0];
// pass to solver
northWall[15 - y][x] = a[15 - y][x]; // x=1,y=1
eastWall[14 - y][x] = b[14 - y][x];
}- Düzenleyen Melsoon 04 Nisan 2012 Çarşamba 09:13
-
04 Nisan 2012 Çarşamba 10:55
Hi Melsoon
Just in case nobody has mentioned it, the compilation error means that you are trying to assign value to an array pointer which is constant. As Brian Muth put it, you need to replace
NorthWall = northWall;//compiler error because NorthWall is constant
with
memcpy(NorthWall,northWall,sizeof(NorthWall));
Or, if some permanent memory space is created in the program for NorthWall, NorthWall should be declared as a pointer.
Best regards
Chong
-
04 Nisan 2012 Çarşamba 22:01
You also overlooked the fact that a C# int is a 64 bit number, and you are trying to copy it to a 32-bit integer.
Use long long instead.
-
05 Nisan 2012 Perşembe 00:14TIP: All of those explicit zero initializers are
unnecessary, You can use default-initialization.
int *ip = new int[16]; // uninitialized
int *ip = new int[16](); // default initialized
The default initialization for an int is zero,
so the last example sets all the ints in the
allocation to zero.
- Wayne -
05 Nisan 2012 Perşembe 00:25
You also overlooked the fact that a C# int is a 64 bit number, and you are trying to copy it to a 32-bit integer.
Brian, I don't think so. See
http://msdn.microsoft.com/en-us/library/exx3b86w.aspx
It seems that long in C# is 64 bits (unlike in Visual C++), but int is 32 bits (same as in Visual C++).
David Wilkinson | Visual C++ MVP -
05 Nisan 2012 Perşembe 01:19
Hi all, thank you for ur help!
how about the error for this....
SearchToGoal(northWall, eastWall);
*error: The best overload method match for 'CreateMaze.Form1.SearchToGoal(ref int[], ref int[])' has some invalid arguments
I imported the dll file over to my C#...
[DllImport("solver.dll")]
public static extern void SearchToGoal(ref int[] a1, ref int[] b1);How am i suppose to even correct or write this?
northWall[15][0] = a[15][0]; // x=0,y=0
eastWall[14][0] = b[14][0];
// pass to solver
// solver(...)
SearchToGoal(northWall, eastWall);
// solver return mouse command
//mouse move .. update x ,y
northWall[15 - y][0] = a[15 - y][0]; // x=0,y=1
eastWall[14 - y][0] = b[14 - y][0];
// pass to solver
northWall[15 - y][x] = a[15 - y][x]; // x=1,y=1
eastWall[14 - y][x] = b[14 - y][x];Please help! THANKS!
- Düzenleyen Melsoon 05 Nisan 2012 Perşembe 01:21
-
05 Nisan 2012 Perşembe 02:35
Brian, I don't think so. See
You're correct, David. My goof.
http://msdn.microsoft.com/en-us/library/exx3b86w.aspx
-
05 Nisan 2012 Perşembe 08:49
Hi Melsoom,
I found you have posted sevaral threads which have the similar topic these days in Visual C++ and Visual C# fourms. Didn't you solve this issue?
please refer to your former threads for information. what's more, do not post the same questions more than once.
Passing of arrays: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/d182abf2-b8c6-4de2-8e84-453f24005fa6.
How to pass this array to my solver in C++: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/08273b32-9b2d-49e6-bf1b-0583afcc55b9.
finally, please mark the reply which helps you as answer,.
Please mark this reply as answer if it helps you! Thanks for your cooperation! Good Luck to you.
-
05 Nisan 2012 Perşembe 08:52
hi, there are still some errors that have not been solved.
Regards,
Melsoon -
05 Nisan 2012 Perşembe 09:20
If the error is on VC# side, you should move to Visual C# forum for better support.
NorthWall = northWall; //y
EastWall = eastWall; //x}
***The errors are the bold worlds.. ERROR: expression must be a modifiable lvalue***
has this error been solved?
We are not allowed to assign C# value to C++ variable directly.
you can try C++/CLI wrapper.
Please mark this reply as answer if it helps you! Thanks for your cooperation! Good Luck to you.
-
05 Nisan 2012 Perşembe 09:29Moderatör
Hi Melsoon,
I agree with Rebecca. You can try C++/CLI wrapper in this situation. That is, we should create a C++/CLI wrapper for the C# class library(C# DLL), and invokes it through the warpper from the native C++ codes. If you want to know more information about this solution, please refer to this link which contains a sample routime: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/0a0342e4-caec-42d0-bfe5-e0930883f141. What's more, you can also try the ways of Solution 2 and 3.
I hope this reply is helpful to you. If you have any questions, please feel free to let me know.
Best regards,Helen Zhao [MSFT]
MSDN Community Support | Feedback to us
- Yanıt Olarak Öneren Helen ZhaoModerator 05 Nisan 2012 Perşembe 09:29
- Yanıt Olarak İşaretleyen Helen ZhaoModerator 11 Nisan 2012 Çarşamba 01:47
-
05 Nisan 2012 Perşembe 11:55
hi, there are still some errors that have not been solved.
The C++/CLI type corresponding to a two dimensional C# array of integers is
Regards,
Melsoon
array<int, 2>
So in your C++/CLI module I think you should do
typedef array<int, 2> Matrix;
void SearchToGoal(Matrix^ northWall, Matrix^ eastWall)
{
// fill elements of northWall, eastWall
}
David Wilkinson | Visual C++ MVP- Yanıt Olarak İşaretleyen Helen ZhaoModerator 11 Nisan 2012 Çarşamba 01:47