1- using System . Runtime . InteropServices ;
1+ using System . Runtime . InteropServices ;
22using Lagrange . Core . Common . Interface ;
33using Lagrange . Core . NativeAPI . NativeModel . Common ;
44using Lagrange . Core . NativeAPI . NativeModel . Message ;
@@ -45,7 +45,7 @@ int subType
4545 {
4646 return ;
4747 }
48-
48+
4949 byte [ ] ? sum = summary . IsEmpty ( ) ? null : summary . ToByteArrayWithoutFree ( ) ;
5050
5151 var context = Program . Contexts [ index ] ;
@@ -82,7 +82,7 @@ int subType
8282 subType
8383 ) ;
8484 }
85-
85+
8686 [ UnmanagedCallersOnly ( EntryPoint = "AddRecord" ) ]
8787 public static void AddRecord ( int index , int id , ByteArrayNative byteArrayNative )
8888 {
@@ -109,7 +109,7 @@ public static void AddLocalRecord(int index, int id, ByteArrayNative byteArrayNa
109109 byteArrayNative . ToByteArrayWithoutFree ( )
110110 ) ;
111111 }
112-
112+
113113 [ UnmanagedCallersOnly ( EntryPoint = "AddVideo" ) ]
114114 public static void AddVideo (
115115 int index ,
@@ -122,7 +122,7 @@ ByteArrayNative thumbnail
122122 {
123123 return ;
124124 }
125-
125+
126126 byte [ ] ? thumb = thumbnail . IsEmpty ( ) ? null : thumbnail . ToByteArrayWithoutFree ( ) ;
127127
128128 var context = Program . Contexts [ index ] ;
@@ -170,12 +170,19 @@ public static IntPtr SendFriendMessage(int index, int id, long friendUin)
170170 {
171171 return IntPtr . Zero ;
172172 }
173-
174- var message = context . BotContext . SendFriendMessage ( friendUin , chain ) . GetAwaiter ( ) . GetResult ( ) ;
175-
176- IntPtr messagePtr = Marshal . AllocHGlobal ( Marshal . SizeOf < BotMessageStruct > ( ) ) ;
177- Marshal . StructureToPtr ( ( BotMessageStruct ) message , messagePtr , false ) ;
178- return messagePtr ;
173+
174+ try
175+ {
176+ var message = context . BotContext . SendFriendMessage ( friendUin , chain ) . GetAwaiter ( ) . GetResult ( ) ;
177+
178+ IntPtr messagePtr = Marshal . AllocHGlobal ( Marshal . SizeOf < BotMessageStruct > ( ) ) ;
179+ Marshal . StructureToPtr ( ( BotMessageStruct ) message , messagePtr , false ) ;
180+ return messagePtr ;
181+ }
182+ catch
183+ {
184+ return IntPtr . Zero ;
185+ }
179186 }
180187
181188 [ UnmanagedCallersOnly ( EntryPoint = "SendGroupMessage" ) ]
@@ -193,11 +200,18 @@ public static IntPtr SendGroupMessage(int index, int id, long groupUin)
193200 return IntPtr . Zero ;
194201 }
195202
196- var message = context . BotContext . SendGroupMessage ( groupUin , chain ) . GetAwaiter ( ) . GetResult ( ) ;
203+ try
204+ {
205+ var message = context . BotContext . SendGroupMessage ( groupUin , chain ) . GetAwaiter ( ) . GetResult ( ) ;
197206
198- IntPtr messagePtr = Marshal . AllocHGlobal ( Marshal . SizeOf < BotMessageStruct > ( ) ) ;
199- Marshal . StructureToPtr ( ( BotMessageStruct ) message , messagePtr , false ) ;
200- return messagePtr ;
207+ IntPtr messagePtr = Marshal . AllocHGlobal ( Marshal . SizeOf < BotMessageStruct > ( ) ) ;
208+ Marshal . StructureToPtr ( ( BotMessageStruct ) message , messagePtr , false ) ;
209+ return messagePtr ;
210+ }
211+ catch
212+ {
213+ return IntPtr . Zero ;
214+ }
201215 }
202216 }
203217}
0 commit comments