回答編集履歴

1

二次元化

2022/12/14 13:36

投稿

matukeso
matukeso

スコア1590

test CHANGED
@@ -1,48 +1,67 @@
1
- こちらは特に正常に受け取れていますが
1
+ 二次元配列だ、と言う話なので。
2
-
3
2
  こういうDLLをつくって、
4
3
  ```C
5
4
  #include <windows.h>
6
5
  #include <stdio.h>
6
+
7
7
  // NPOS_DETAIL_UPD2の定義を省略
8
8
  __declspec(dllexport) int __stdcall Esql_UpNonPos
9
- (void *lpHeader, long *nIndexNum, NPOS_DETAIL_UPD2 *lpDetail)
9
+ (void *lpHeader, int *nIndexNum, NPOS_DETAIL_UPD2 *lpDetail)
10
10
  {
11
- NPOS_DETAIL_UPD2 npos;
12
- int ii;
11
+ int ii,jj;
13
- for(ii=0; ii<*nIndexNum; ii++) {
12
+ for(ii=0; ii<nIndexNum[0]; ii++) {
14
- npos = lpDetail[ii]; //←I get an error here.
13
+ for (jj = 0; jj < nIndexNum[1]; jj++) {
15
-
16
- printf("%S\n", npos.szFunctionFlag);
14
+ printf("%d,%d=%S\n", ii, jj, lpDetail[ii * nIndexNum[1] + jj].szFunctionFlag);
15
+ wchar_t msg[128];
16
+ int len = swprintf_s(msg, sizeof(msg), L"cd%d.%d", ii, jj);
17
+ if (lpDetail[ii * nIndexNum[1] + jj].szFunctionFlag) SysFreeString(lpDetail[ii * nIndexNum[1] + jj].szFunctionFlag);
18
+ lpDetail[ii*nIndexNum[1] + jj].szFunctionFlag = SysAllocStringLen(msg, len ); //
17
- }
19
+ }
20
+ }
18
21
  return 0;
19
22
  }
23
+
20
24
  ```
21
25
 
22
26
  こういう呼び出しをすると
23
27
  ```vb
28
+ <DllImport("m.dll", CharSet:=CharSet.Unicode)>
24
- Public Shared Function Esql_UpNonPos(<[In]()> ByVal Up_dtpPSHead As System.IntPtr, ByRef RecordCnt As Long, <[In]()> ByVal Up_dtpNonPosDet() As tpNonPosDet2) As Integer
29
+ Public Shared Function Esql_UpNonPos(<[In]()> ByVal Up_dtpPSHead As System.IntPtr, <[In]()> ByVal RecordCnt() As Integer, <[In](), [Out]()> ByVal Up_dtpNonPosDet() As tpNonPosDet2) As Integer
25
30
  End Function
26
31
 
27
32
  Public Shared Sub Main(args() As String)
28
- Dim det(10) As tpNonPosDet2
33
+ Dim det2d(2, 4) As tpNonPosDet2
29
- Dim count As Long = det.Length
34
+ For i As Integer = 0 To det2d.GetLength(0) - 1
35
+ For j As Integer = 0 To det2d.GetLength(1) - 1
36
+ det2d(i, j).strShoriFlg = String.Format("det{0}.{1}", i, j)
37
+ Next
38
+ Next
30
39
 
40
+ Dim dims() As Integer = New Integer() {det2d.GetLength(0), det2d.GetLength(1)}
41
+ Dim det(dims(0) * dims(1)) As tpNonPosDet2
42
+ System.Console.WriteLine("dim {0}x{1}", dims(0), dims(1))
43
+
31
- For i As Integer = 0 To det.Length - 1
44
+ For i As Integer = 0 To det2d.GetLength(0) - 1
45
+ For j As Integer = 0 To det2d.GetLength(1) - 1
32
- det(i).strShoriFlg = "helo" & CStr(i)
46
+ det(i * dims(1) + j).strShoriFlg = String.Format("det{0}.{1}", i, j)
47
+ Next
33
48
  Next
49
+
34
- Esql_UpNonPos(System.IntPtr.Zero, count, det)
50
+ Esql_UpNonPos(System.IntPtr.Zero, dims, det)
51
+
52
+ For i As Integer = 0 To dims(0) - 1
53
+ For j As Integer = 0 To dims(1) - 1
54
+ det2d(i, j) = det(i * dims(1) + j)
55
+ System.Console.WriteLine(det2d(i, j).strShoriFlg)
56
+ Next
57
+ Next
35
58
  End Sub
36
59
  ```
37
60
  こういう結果になります。
61
+ > dim 3x5
62
+ > 0,0=det0.0
38
- >helo0
63
+ > ...
39
- >helo1
40
- >helo2
41
- >helo3
42
- >helo4
64
+ > 2,4=det2.4
43
- >helo5
44
- >helo6
45
- >helo7
46
- >helo8
47
- >helo9
48
- >helo10
65
+ > cd0.0
66
+ > ...
67
+ > cd2.4